Thursday, March 12, 2009

Letting Maven use local libraries

Sometimes it is useful to have Maven use some JARs that are checked in with the project, e.g. since you don't trust anything else or you just can't find a library in an existing repository and don't want to run your own.

It actually turns out to be pretty easy. Add something like this to your pom.xml:

<name>Local repository in project tree</name>

Afterwards Maven will try to find a repository in the "lib" folder in your project. Let's assume you want this dependency in the local repository (hopefully something with better chosen IDs, but I decided to keep an existing pattern here):


What you need for this is a folder structure representing those three bits of information: groupId, artifactId and version (in that order), i.e. lib/owlapi/owlapi/2.2.0. In that folder Maven expects at least four things: the JAR file, a matching POM file and the SHA1 sums for both. All files are named using the artifactId and the version, i.e. "owlapi-2.2.0.jar" for the JAR, the same for the POM but with the different extension.

To get the SHA1 sums you can do this (assuming you run bash and have the sha1sum tool available):

for file in `ls`; do sha1sum $file > $file.sha1; done

If you are nice and add the sources (has to be a JAR with "-sources" in the name), then the result looks something like this:

The POM itself just contains the basic description (and possible dependencies):

<description>Java interface and implementation for the Web Ontology Language OWL</description>
<name>GNU Lesser General Public License, Version 3</name>

That's all there is -- next time you run Maven it should "download" the files from that location. Considering that the POM also provides a uniform way of storing licence, source and version information it is actually a quite useful approach for storing dependencies inside your project's space.


Zack said...

Very helpful. You saved me quite a bit of annoying manual local repository entries.

Patrick Co Eban said...

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training from India . Nowadays Java has tons of job opportunities on various vertical industry.

Cheryl Terrell said...

Amazing products, excellent help, simple to operate SOSav Ersatzteile Smartphones website. I'm pleased about my product, what exactly I used to be expecting……

bakoryvalder said...

888 Casino Online NJ | NJ's Best Casino in 2021
Enjoy online slots for 경주 출장안마 real money and win 당진 출장마사지 real money in New 서산 출장샵 Jersey. 순천 출장마사지 We have 김포 출장샵 more than 2000 casino games in our database and the biggest winner today.

yk6g9mtsuy said...

And ought to use|you must use} EVC to ask buddies if they're ready and willing to have a sure conversation with you. EVC also serves as a check-in if conditions seem ambiguous, you’re coping with unfamiliar individuals or new buddies, or you wish to initiate a new new} type of interplay. This value defines the dimension of fabric left between the management geometry and the precise reduce. Typically, you want your reduce to precisely match your geometry. The Clearance Satin Boxers For Men Plane describes the X-Y plane the place software travel motions can safely happen across the CNC bed .