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!
With Eclipse Oxygen you can do the below things:
Maven will take them when installing the project.
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)
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 folderservice-sdk/service-sdk/0.0.1/
and place the jar fileservice-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:
Enjoy
If you meet the same problem and you are using spring-boot v1.4+, you can do it in this way.
There is an includeSystemScope that you can use to add system-scope dependencies to the jar.
e.g.
I'm using oracle driver into my project.
then make includeSystemScope=true to include the jar into path /BOOT-INF/lib/**
and exclude from resource to avoid duplicated include, the jar is fat enought~
Good luck!
Maven way to add non maven jars to maven project
Maven Project and non maven jars
Add the maven install plugins in your build section
Add the dependency
References Note I am the owner of the blog
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
The Maven manual says to do this: