Creating runnable .jar with dependant libraries?

B

Bas

Hi,

I'm trying to create a jar so the end user can simply start the
application like this:

java -jar somejar.jar

This is all fine except how can I embed libraries (in jars) in this jar
file and have them appear in the classpath? Or do I need to unjar those
libraries individually and jar them into the new archive?

My brain must be f*cked up after creating .war's and .ear's for too
long ;)

Cheers,

Bas.
 
R

Rogan Dawes

Bas said:
Hi,

I'm trying to create a jar so the end user can simply start the
application like this:

java -jar somejar.jar

This is all fine except how can I embed libraries (in jars) in this jar
file and have them appear in the classpath? Or do I need to unjar those
libraries individually and jar them into the new archive?

My brain must be f*cked up after creating .war's and .ear's for too
long ;)

Cheers,

Bas.

Couple of options

put your library jars in the classpath in the manifest, and place the
jars themselves in a directory relative to your application jar. NOT in
the jar itself!

Alternatively, look for One-Jar or UberJar which can do what you are
looking for.

A third possibility is to use something like Proguard which will package
up all of your required classes into a single monolithic jar (but it
breaks if the jars need to be signed, etc)

Rogan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top