views:

730

answers:

2

If I was to use a 3rd party library that was not in the maven public repository, what is the best way to include it as dependency for my project so that when someone else checks out my code it will still be able to build?

i.e.

My Application "A" depends on jar "B" which does not exist in the public repository. I, however, wish to add "B" as a dependency to "A" such that when a person on the other side of the world could check out the code and still be able to build "A"

+4  A: 

You can install the project yourself.

Or you can use the system scope like the following:

<dependency>
    <groupId>org.group.project</groupId>
    <artifactId>Project</artifactId>
    <version>1.0.0</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/project-1.0.0.jar</systemPath>
</dependency>

systemPath requires the absolute path of the project. To make it easier, if the jar file is within the repository/project, you can use ${basedir} property, which is bound to the root of the project.

notnoop
+7  A: 

Using system scope may work but it is not recommended even in the Maven specification. it is not portable.

from Maven book:

system-  The system scope is similar to provided except that you have to provide an 
explicit path to the JAR on the local file system. This is intended to allow compilation
against native objects that may be part of the system libraries. The artifact is assumed 
to always be available and is not looked up in a repository. If you declare the scope to 
be system, you must also provide the systemPath element. Note that this scope is not 
recommended (you should always try to reference dependencies in a public or custom Maven
repository).

The best approach is to install to your local repository or to your enterprise repository to be accessible to all your peers.

this is very easy if you are using some repository using Nexus. Tell me if you need more info...

Ronen.

rperez
If I were to install it to my local repo, how would others build the project if they did not have access to my local repo? for example, if I had an application that I made publicly available online and then you (rperez) wanted to download that project and build it, how would you access my local repo to build it?
digiarnie
that is why I suggested using an enterprise repository. when you have an ent. repository like Nexus that we are using, it function in two ways:1) proxy to the public repositories - download all needed 3'rd party libraries and store them for uture use2) store all of your organization's artifactsin addition you can also store libraries that are not on the public domain. this repository is accessible to whoever you want. you can put it in the company intranet or giv it a public URL - your choice.
rperez