maven-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Eggers <>
Subject Re: How to run jar dependent on maven repo jars? How to extract dependent jars into folder to include in classpath?
Date Mon, 11 May 2015 20:08:34 GMT
Hash: SHA1

On 5/11/2015 12:46 PM, Richard Catlin wrote:
> I built a jar using a pom.  The jar depends on jars in the maven 
> repository.  How do I run my jar and include the jars in the maven 
> repository in the classpath?  If it possible to extract all the
> dependent jars into a /lib directory that I can add to my classpath
> at runtime?
> Thanks. Richard


I can think of two ways to do this.

1. Uber jar (I've not tried this)

See the Shade plugin at:

2. Assembly plugin (this is what I do)

A. JAR Plugin
In your POM, configure the JAR plugin to contain three pieces of

a) mainClass - this is obviously the class that has the main method
b) addClassPath - set this to true
c) classpathPrefix - I've set mine to lib

B. Dependency Plugin
In your POM, configure the dependency plugin to copy all of the
dependencies to the subdirectory of the target directory. The
subdirectory name should be the same as the classpathPrefix value

For example:


(This is an old project, update as appropriate).

C. Assembly Plugin

Configure the assembly plugin to create a zip file, tar.gz file,
whatever . . .

In src/main/assembly/assembly.xml, put in something like the following
(note that I've left out the namespaces for brevity):


C. Construct your package:

mvn package
mvn assembly:single

This will leave you a .tar.gz file and a .zip file (using the
assembly.xml above).

D. Unzip (or untar) and run

Now when you unarchive your .tar.gz file or .zip file, you'll end up
with a JAR file (your code) and a lib subdirectory with all of the
compile time dependencies. You should be able to run the JAR file from
the command line with:

java -jar [your-jar-file-name]

I'm a relative newcomer to Maven, but I hope this helps.

. . . just my two cents.
Version: GnuPG v2


This email is free from viruses and malware because avast! Antivirus protection is active.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message