Maven: add a dependency to a jar by relative path

后端 未结 9 1037
半阙折子戏
半阙折子戏 2020-11-21 23:21

I have a proprietary jar that I want to add to my pom as a dependency.

But I don\'t want to add it to a repository. The reason is that I want my usual maven commands

9条回答
  •  后悔当初
    2020-11-22 00:16

    This is another method in addition to my previous answer at Can I add jars to maven 2 build classpath without installing them?

    This will get around the limit when using multi-module builds especially if the downloaded JAR is referenced in child projects outside of the parent. This also reduces the setup work by creating the POM and the SHA1 files as part of the build. It also allows the file to reside anywhere in the project without fixing the names or following the maven repository structure.

    This uses the maven-install-plugin. For this to work, you need to set up a multi-module project and have a new project representing the build to install files into the local repository and ensure that one is first.

    You multi-module project pom.xml would look like this:

    pom
    
    
        repository
        ... other modules ...
    
    

    The repository/pom.xml file will then contain the definitions to load up the JARs that are part of your project. The following are some snippets of the pom.xml file.

    repository
    pom
    

    The pom packaging prevents this from doing any tests or compile or generating any jar file. The meat of the pom.xml is in the build section where the maven-install-plugin is used.

    
        
            
                org.apache.maven.plugins
                maven-install-plugin
                
                    
                            com.ibm.db2:db2jcc
                            verify
                            
                                install-file
                            
                            
                                com.ibm.db2
                                db2jcc
                                9.0.0
                                jar
                                ${basedir}/src/jars/db2jcc.jar
                                true
                                true
                            
                    
                    ...
                
            
        
    
    

    To install more than one file, just add more executions.

提交回复
热议问题