Maven, how to add additional libs not available in repo

拜拜、爱过 提交于 2019-12-29 00:06:40

问题


I have a maven project that has a set of library dependancies that are not available via any maven repository. How can I add those libraries to the pom? I want to do this so when I run 'mvn eclipse:eclipse' it doesnt remove those libraries from the eclipse classpath.


回答1:


You have 3 options:

  • Add your libraries to your local repository via install:install-file (obviously, this is not portable, you won't be able to build the project on another machine without doing the same).
  • Install and run an "enterprise repository" like Nexus, Archiva, or Artifactory and add your libraries via deploy:deploy-file.
  • Setup a file based repository as described in this previous answer and put your libraries in there.

Then, declare your libraries in your pom like any other dependency.




回答2:


You can declare it as a dependency with system scope.

<project>
...
 <dependencies>
   <dependency>
     <groupId>sun.jdk</groupId>
     <artifactId>tools</artifactId>
     <version>1.5.0</version>
     <scope>system</scope>
     <systemPath>${java.home}/../lib/tools.jar</systemPath>
   </dependency>
 </dependencies>
 ...
</project>



回答3:


You can include them with your project in a sub-directory (perhaps lib/). You can also provide .bat and/or .sh files containing all the appropriate calls to the maven-install-plugin necessary for each project member (or server env) to add these jars to the local repo.

This approach allows new project members to get up & running quickly, without having to invest several hours in setting up a new public repo for your project or team.




回答4:


You can't 'add them to the pom'. You have to put them in some repo. You can put them in the local repo with the maven-install-plugin, as suggested by the error message. Or you can deploy them in a local copy of Nexus or something like it.




回答5:


recently I created a small UI Util to install libraries to you local repository. It works the same way as install:install-file.

https://github.com/escv/maven-install-ui



来源:https://stackoverflow.com/questions/2479046/maven-how-to-add-additional-libs-not-available-in-repo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!