Maven: Including jar not found in public repository

前端 未结 6 1367
暖寄归人
暖寄归人 2020-12-02 07:23

If I was to use a 3rd party library that was not in the maven public repository, what is the best way to include it as dependency for my project so that when someone else ch

6条回答
  •  萌比男神i
    2020-12-02 08:03

    If you have a parent project with a module that is in this situation (requires a dependency not in a repository) you can setup your parent project to use the exec-maven-plugin plugin to auto-install your dependent file. For example, I had to do this with the authorize.net jar file since it is not publicly available.

    Parent POM:

    
        
            
                org.codehaus.mojo
                exec-maven-plugin
                1.2.1
                false
                
                    
                        install-anet
                        validate
                        
                            exec
                        
                    
                
                
                    mvn
                    
                        install:install-file
                        -Dfile=service/lib/anet-java-sdk-1.4.6.jar
                        -DgroupId=net.authorize
                        -DartifactId=anet-java-sdk
                        -Dversion=1.4.6
                        -Dpackaging=jar
                    
                
            
        
    
    

    In the above example, the location of the jar is in the lib folder of the "service" module.

    By the time the service module enters the validate phase, the jar will be available in the local repository. Simply reference it in the way you set up the groupid, artifact, etc in the parent pom. For example:

    
        net.authorize
        anet-java-sdk
        1.4.6
    
    

提交回复
热议问题