How to add local jar files to a Maven project?

后端 未结 30 3319
悲&欢浪女
悲&欢浪女 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:22

    Another interesting case is when you want to have in your project private maven jars. You may want to keep the capabilities of Maven to resolve transitive dependencies. The solution is fairly easy.

    1. Create a folder libs in your project
    2. Add the following lines in your pom.xml file

      ${pom.basedir}/libs/
      
      
      
         
              local-maven-repository
              file://${local.repository.folder}
              
                  true
              
              
                  true
              
         
      
      
    3. Open the .m2/repository folder and copy the directory structure of the project you want to import into the libs folder.

    E.g. suppose you want to import the dependency

    
        com.mycompany.myproject
        myproject
        1.2.3
    
    

    Just go on .m2/repository and you will see the following folder

    com/mycompany/myproject/1.2.3

    Copy everything in your libs folder (again, including the folders under .m2/repository) and you are done.

提交回复
热议问题