Approach 2: Include jar as part of the maven project. In this approach you need to first create a folder in your maven project & add your external jar file. Once the jar file is added, include the jar file in your pom using following notation.
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
<repository>
<id>in-project</id>
<name>In Project Repo</name>
<url>file://${project.basedir}/libs</url>
</repository>
<dependency>
<groupId>dropbox</groupId>
<artifactId>dropbox-sdk</artifactId>
<version>1.3.1</version>
</dependency>
/groupId/artifactId/version/artifactId-verion.jar
detail read this blog post
https://web.archive.org/web/20121026021311/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:
<dependencies>
<dependency>
<groupId>ldapjdk</groupId>
<artifactId>ldapjdk</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${basedir}\src\lib\ldapjdk.jar</systemPath>
</dependency>
</dependencies>
Reference: http://www.tutorialspoint.com/maven/maven_external_dependencies.htm
The Maven manual says to do this:
mvn install:install-file -Dfile=non-maven-proj.jar -DgroupId=some.group -DartifactId=non-maven-proj -Dversion=1 -Dpackaging=jar
update We have since just installed our own Nexus server, much easier and cleaner.
At our company we had some jars that we some jars that were common but were not hosted in any maven repositories, nor did we want to have them in local storage.
We created a very simple mvn (public) repo on Github (but you can host it on any server or locally):
note that this is only ideal for managing a few rarely chaning jar files
Create repo on GitHub:https://github.com/<user_name>/mvn-repo/
Add Repository in pom.xml
(Make note that the full path raw file will be a bit different than the repo name)
<repository>
<id>project-common</id>
<name>Project Common</name>
<url>https://github.com/<user_name>/mvn-repo/raw/master/</url>
</repository>
Add dependency to host (Github or private server)
a. All you need to know is that files are stored in the pattern mentioned by @glitch/groupId/artifactId/version/artifactId-version.jar
b. On your host create the folders to match this pattern.
i.e if you have a jar file named service-sdk-0.0.1.jar
, create the folder service-sdk/service-sdk/0.0.1/
and place the jar file service-sdk-0.0.1.jar
into it.
c. Test it by trying to download the jar from a browser (in our case: https://github.com/<user_name>/mvn-repo/raw/master/service-sdk/service-sdk/0.0.1/service-sdk-0.0.1.jar
Add dependency to your pom.xml file:
<dependency>
<groupId>service-sdk</groupId>
<artifactId>service-sdk</artifactId>
<version>0.0.1</version>
</dependency>
Enjoy
Don't use systemPath. Contrary to what people have said here, you can put an external jar in a folder under your checked-out project directory and haven Maven find it like other dependencies. Here are two crucial steps:
It is fairly straightforward and you can find a step-by-step example here: http://randomizedsort.blogspot.com/2011/10/configuring-maven-to-use-local-library.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With