wood burning stoves 2.0*
The moose likes Java in General and the fly likes Executable jar that contains other jars Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Executable jar that contains other jars" Watch "Executable jar that contains other jars" New topic
Author

Executable jar that contains other jars

Imre Tokai
Ranch Hand

Joined: Jun 04, 2008
Posts: 130
Hello!


How can I create a app.jar that contains jarlib1.jar jarlib2.jar...
In the manifest file I have:
This is working, but I have to copy all dependent jars in the app.jar's folder.


How can I create a app.jar that contains all dependent jars and can be executed with:
java -jar app.jar
?


Regards
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37951
    
  22
Is there anything helpful in the Java Tutorials? Look in the section about updating jars. Does that help?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18509
    
  40

This is working, but I have to copy all dependent jars in the app.jar's folder.


Well,. that's how the manifest tag works... it doesn't magically copy all the jars into one big jar. It just defines what jar files to look for.

If you want one big jar, you will have to do it youself -- extract all the jars into one location for classes, and jar the whole wad back together. Personally, I would not recommend doing this. What is wrong with having separate jar files?

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Imre Tokai
Ranch Hand

Joined: Jun 04, 2008
Posts: 130
Thank you for your answers!


And is there any chance to do this with Maven or any OneJar app?

I am looking around, but still haven't find any working solution. It's more elegant to have only one app.jar file, than to have app.jar file and additional lib folder.
I'm also thinking about obfuscating code later...


Regards
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

Imre Tokai wrote:Thank you for your answers!


And is there any chance to do this with Maven or any OneJar app?

I am looking around, but still haven't find any working solution. It's more elegant to have only one app.jar file, than to have app.jar file and additional lib folder.
I'm also thinking about obfuscating code later...


Regards

Take a look at the Maven Maven Assembly Plugin. Specifically you will want to look at the jar-with-dependencies Predefined Assembly Descriptor. The usage page has some discussion on it.

Java 7 is going to be introducing the concept of a Java Module (JAM) -- see JSR 277 -- which will basically deal with this as well. A JAM will apparently be a super-set of JARs. So you'll put your JARs in your JAM rather than your jam in jars like Smuckers does ;)
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8801
    
    5
intermediate level


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Imre Tokai
Ranch Hand

Joined: Jun 04, 2008
Posts: 130
I used Maven and created one-jar successfully!

But i haven't had success without Maven.
In manifest file i added
Main-Class: package1.Mainclassname
Class-Path: lib/jar1.jar lib/jar2.jar...
and copied necessary jars to the lib folder (which is in the same folder where app.jar is).
Jars are not recognized.

How can I create one-jar without Maven?


Regards
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624


What is the error message you are getting when you try to run it?

The manifest information you are showing looks good. Try doing a diff between the manifest you are creating and the one Maven created. See if anything jumps out. One thing to note is when you wrap an entry onto the next line (after 70 characters), you need a space at the start of that next line. For example:


Notice the spaces at the start of lines 4, 8, & 9.
 
jQuery in Action, 2nd edition
 
subject: Executable jar that contains other jars
 
Similar Threads
including jar files in jar files
RMI problem
ProGuard
Any alternative to launch client ??
help please...