It's my first couple of days learning Maven and I'm still struggling with the basics. I have an external .jar file (not available in the public repos) that I need to reference in my project and I'm trying to figure out what my best option is.
It's a small scale project without a central repository for libraries, so it has to be either a local repository (somehow added to source control, don't know if it's supposed to work that way?) or the .jar needs to be stored on disk outside of any formal repository.
1) What's my best option for adding the .jar file to my project's references with maven given that I want both the project and the library to be in source control?
2) I still can't seem to have Eclipse see the dependency. I manually added it to the section of the pom, and it shows up fine in the Dependencies list in m2eclipse. mvn compile and mvn package both succeed, but running the program results in:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
LibraryStuff cannot be resolved to a type
This is after editing the POM as:
<dependency>
<groupId>stuff</groupId>
<artifactId>library</artifactId>
<version>1.0</version>
<systemPath>${lib.location}/MyLibrary.jar</systemPath>
<scope>system</scope>
</dependency>
Should I be executing mvn install:install-file even thought I already have the pom.xml edited as above?
Thanks!
You can create an In Project Repository, so you don't have to
run mvn install:install-file
every time you work on a new computer/groupId/artifactId/version/artifactId-verion.jar
detail read this blog post
http://charlie.cu.cc/2012/06/how-add-external-libraries-maven/
I think you should use
mvn install:install-file
to populate your local repository with the library jars then you should change the scope from system to compile.If you are starting with maven I suggest to use maven directly not IDE plugins as it adds an extra layer of complexity.
As for the error, do you put the required jars on your classpath? If you are using types from the library, you need to have access to it in the runtime as well. This has nothing to do with maven itself.
I don't understand why you want to put the library to source control - it is for sources code not binary jars.
This can be easily achieved by using the <scope> element nested inside <dependency> element.
For example:
Reference: http://www.tutorialspoint.com/maven/maven_external_dependencies.htm
The best solution here is to install a repository: Nexus or Artifactory. If gives you a place to put things like this, and further it speeds things up by caching your stuff from the outside.
If the thing you are dealing with is open source, you might also consider putting in into central.
See the guide.
Note that all of the example that use
require outer
enclosing tags. It's not clear from some of the examples.
If the external jar is created by a Maven project only then you can copy the entire project on your system and run a
in the project directory. This will add the jar into .m2 directory which is local maven repository.
Now you can add the
This will ensure that you
works. If you use suggested here
Then you will have to add classes individually while using executing through command line.
You can add the external jars by the following command described here