Using a lib directory with Maven

People seem unaware that it is pretty easy to use a lib directory in Maven builds. Many ant builds use structures like below:


+---lib
+---src
    +---conf
    +---java
    +---test

I find this a useful layout, especially if you have jars that do not exist in the main Maven repository.

In Maven, you might have a dependency declared like this:


<dependency>
	<id>cas</id>
	<artifactId>cas</artifactId>
</dependency>

In your projects.properties file you can override the location of each jars like this:


maven.jar.override=on
maven.jar.cas=lib/cas-2.0.12.jar

You need to add an entry for each jar you want to override the location of. I haven't figured out how to make it work for all the alternate types of dependency declarations, though.

Obviously this (like too many things in Maven) is something that should be a lot easier than it is. I think that the project.xml should be able to specify a build-repository that is checked before the local repository, since that would make self-contained builds a lot easier. In the mean time, this is a useful measure that I've found useful.

Leave a Reply

Your email address will not be published. Required fields are marked *