How to add local jar files to a Maven project?

后端 未结 30 3384
悲&欢浪女
悲&欢浪女 2020-11-21 04:58

How do I add local jar files (not yet part of the Maven repository) directly in my project\'s library sources?

30条回答
  •  忘掉有多难
    2020-11-21 05:06

    1. Create a local Maven repository directory, Your project root should look something like this to start with:
    yourproject
    +- pom.xml
    +- src
    
    1. Add a standard Maven repository directory called repo for the group com.example and version 1.0:
    yourproject
    +- pom.xml
    +- src
    +- repo
    
    1. Deploy the Artifact Into the Repo, Maven can deploy the artifact for you using the mvn deploy:deploy-file goal:
    mvn deploy:deploy-file -Durl=file:///pathtoyour/repo -Dfile=your.jar -DgroupId=your.group.id -DartifactId=yourid -Dpackaging=jar -Dversion=1.0
    
    1. install pom file corresponding to your jar so that your project can find jar during maven build from local repo:
    mvn install:install-file -Dfile=/path-to-your-jar-1.0.jar -DpomFile=/path-to-your-pom-1.0.pom
    
    1. add repo in your pom file:
    
        
        
            project.local
            project
            file:${project.basedir}/repo
        
    
    
    1. add the dependency in your pom:
    
        com.groupid
        myid
        1.0
    
    

提交回复
热议问题