views:

1720

answers:

3

I have a proprietary jar that I want to add to my pom as a dependency.

But I don't want to add it to a repository. The reason is that I want my usual maven commands such as mvn compile, etc, to work out of the box. (Without demanding from the developers a to add it to some repository by themselves).

I want the jar to be in a 3rdparty lib in source control, and link to it by relative path from the pom.xml file.

Can this be done? How?

+2  A: 

Using the system scope. ${basedir} is the directory of your pom.

<dependency>
    <artifactId>..</artifactId>
    <groupId>..</groupId>
    <scope>system</scope>
    <systemPath>${basedir}/lib/dependecny.jar</systemPath>
</dependency>

However it is advisable that you install your jar in the repository, and not commit it to the SCM - after all that's what maven tries to eliminate.

Bozho
The scope system must be avoided everywhere it is possible. Install the JAR in the repository is a better solution...
Gandalf StormCrow
yes, if possible. he said explicitly that he doesn't want to put it in the repository. I added a comment to point out that this is not a good practice. But it does work.
Bozho
groovy, you solution is the most acceptable so far I guess .. I totally misread the question
c0mrade
+21  A: 
Pascal Thivent
very interesting idea
flybywire
"Really, this is a better solution than using a system scope" - indeed (+1)
Bozho
great idea! Haven't thought of that :-)
Patrick Cornelissen
This is a great idea, but on Maven 2.2.1, the install plugin seems to be ignoring `localRepositoryPath`...
Jake
@Jake Indeed, looks like a bug in version 2.2 of the plugin. I've updated my answer with a version that works.
Pascal Thivent
@Pascal Great! Thanks for the solution.
Jake
+2  A: 

I've previously written about a pattern for doing this: http://brettporter.wordpress.com/2009/06/10/a-maven-friendly-pattern-for-storing-dependencies-in-version-control/

It is very similar to the solution proposed by Pascal, though it moves all such dependencies into a dedicated repository module so that you don't have to repeat it everywhere the dependency is used if it is a multi-module build.

Brett Porter
Interesting, thanks for sharing this.
Pascal Thivent