aspose file tools*
The moose likes Java in General and the fly likes Including library jars in an application jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Including library jars in an application jar" Watch "Including library jars in an application jar" New topic
Author

Including library jars in an application jar

Michael Zellmann
Greenhorn

Joined: Dec 17, 2004
Posts: 18
I have an application that I want to package into a single jar for deployment. I have read through other posts and solved my problems with data files by using the class loader and getRsourceAsStream(String path). Now I need to do soemthing similar with my supporting library jars. I have tried to include the class path information in the Manifest, but I am not successful.

Here are some specifics.

I have three jars - call them a.jar, b.jar and c.jar. I have them in a folder lib at the top level of my structure - same level as all the packages and folders in the application. The main class is common.Driver. My manifest declares

Main-Class: common.Driver
Class-Path: lib/a.jar;lib/b.jar;lib/c.jar

(there is a new line at the last entry)

I have everything jared into one jar - call it app.jar

Then I try

java -jar app.jar

But - this does not work. I get a ClassNotFoundException for the first class that is needed from the library jars.

If I take the three required jars and place them in my jre/lib/ext folder, everything works fine.

What is the correct way to do this?
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10289
    
168

Class-Path: lib/a.jar;lib/b.jar;lib/c.jar


Remove the semi-colon and separate the jar using space. Something like:



[My Blog] [JavaRanch Journal]
Michael Zellmann
Greenhorn

Joined: Dec 17, 2004
Posts: 18
Thanks for getting back to me. I have tried that but still not successful. Here is my exact Manifest


Again, the three jars are in the lib directory in the jar

The first time the application tries to get a class from those libraries, I get a ClassNotFoundException.

If I put the jars in the jre/lib/ext directory, it works.

[ March 23, 2007: Message edited by: Michael Zellmann ]
[ March 23, 2007: Message edited by: Michael Zellmann ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42928
    
  68
I don't think that nested jar files will work - you'll need to repackage everything into a single jar file. But this isn't hard to automate with Ant.
Michael Zellmann
Greenhorn

Joined: Dec 17, 2004
Posts: 18
Thanks. I guess that is true. No nested jars. I unzipped the library jars and re-jarred everything and it works. I guess if I re-read the manifest instructions, class-path refers to the relative urls from which the main jar was downloaded. It isn't meant for "internal" library jars.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Take a look at http://one-jar.sourceforge.net/


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Including library jars in an application jar