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.

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.