This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Including library jars in an application jar

 
Michael Zellmann
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class-Path: lib/a.jar;lib/b.jar;lib/c.jar


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

 
Michael Zellmann
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at http://one-jar.sourceforge.net/
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic