7

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.

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
wuntee
  • 12,170
  • 26
  • 77
  • 106

5 Answers5

8

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>
YuppieNetworking
  • 8,672
  • 7
  • 44
  • 65
  • 2
    Not recommended at all! This is a hack, system scope is not intended for this use and this as drawbacks/side effects. – Pascal Thivent Mar 19 '10 at 17:13
  • 1
    I do not agree with you. The question does not specify anything about the intended use. He needs to add it so that eclipse does not remove it from the classpath. – YuppieNetworking Mar 19 '10 at 17:23
  • For any serious project that may later use things like the assembly plugin, you don't want to use system scope. This is just a bad practice, I do not recommend it. – Pascal Thivent Mar 19 '10 at 20:23
4

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.

Community
  • 1
  • 1
Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
1

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.

Drew Wills
  • 8,408
  • 4
  • 29
  • 40
0

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

Andre Albert
  • 1,386
  • 8
  • 17
  • Please include some code on how this works instead of just a link. – krillgar Jul 02 '14 at 13:59
  • the is no code required because it is a small runnable UI application. The download link is : [https://github.com/escv/maven-install-ui/raw/master/maven-install-ui/dist/maven-install-ui-0.0.1-with-dependencies.jar](https://github.com/escv/maven-install-ui/raw/master/maven-install-ui/dist/maven-install-ui-0.0.1-with-dependencies.jar) – Andre Albert Jul 05 '14 at 16:05
0

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.

bmargulies
  • 97,814
  • 39
  • 186
  • 310