File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Building a jar with dependancies. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Building a jar with dependancies." Watch "Building a jar with dependancies." New topic
Author

Building a jar with dependancies.

Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
I have a program that relies on serveral other jars. hibernate, foxtrot, jgoodies forms, ect...

I am trying to jar my program and run it, but I can't seem to make to dependancies work. What I would like to do is be able to distribute the other jars so they would 'live' in either the same directory as my jar, or in a lib directory (location determined at build time).

I have tried adding all the classes into my manafest file with no luck (making sure all the jars exist in the places indicated by the manifest file). I have dropped all the jars into the JAVA_HOME/lib/ext directory with no luck. Currently what I get is a NoClassDefFoundError. Does anybody have any ideas as to how to make this work? Here is what my manifest file looks like:


Thanks
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Not sure if you've already tried this. (alternatively maybe trying a simpler example would help)

In an example that I know works (weblogic.jar) the classpath is specified all on one line(it wraps, I pasted below what it looke like from winzip default viewer):

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.5.3
Created-By: 1.4.1_05-b01 (Sun Microsystems Inc.)
Main-Class: weblogic.Server
Implementation-Vendor: BEA Systems
Implementation-Title: WebLogic Server 8.1 SP2 Fri Dec 5 15:01:51 PST
2003 316284
Implementation-Version: 8.1.2.0
Class-Path: wlcipher.jar webservices.jar xmlx.jar ojdbc14.jar jconn2.j
ar jConnect.jar EccpressoAsn1.jar EccpressoCore.jar EccpressoJcae.jar
ant/ant.jar ant/optional.jar ant/jakarta-oro-2.0.7.jar ../../common/
perf/java/dirig.jar ../../common/perf/java/dsJMX.jar ../../common/per
f/java/AgtMX.jar wlbase.jar wlutil.jar wlsqlserver.jar wldb2.jar wlsy
base.jar wloracle.jar wlinformix.jar


From Sun jar docs:

The value of this attribute specifies the relative URLs of the extensions or libraries that this application or extension needs. URLs are separate by one or more spaces. The application or extension class loader uses the value of this attribute to construct its internal search path.


Tutorial on jar download extension says these are valid ways to list more than one URL in the Manifest Classpath:

Class-Path: area.jar servlet.jar images/

You can also specify multiple extension URLs by using more than one Class-Path header in the manifest. For example:

Class-Path: area.jar
Class-Path: servlet.jar
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
I had all the jars on one line before with the same problem (I think I also had an error about the length of the line, can't remember for sure). I read that you can span it over multiple lines as long as the other lines begin with a space.

I think I'll try doing the multiple 'Class-Path:' declarations. I hope that works.

Thanks for the help.
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
Ok, if I put all the jar files on one line it tells me that the line is to long. If I put the Class-Path in front of each line I still get the NoClassDefFoundError. Any other ideas? This is really starting to drive me nuts.

I do appreciate the help so far though.
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Exactly what error are you getting? What class isn't being found? Perhaps the stack trace will help.

What jdk version are you using? Are you sure this works when you set the classpath externally in the order you were trying to set it in the manifest?

The more I look at your list of jars I wonder where you are trying to run this and why are you trying to take this route? Running on JBOSS?
[ February 08, 2005: Message edited by: Carol Enderlin ]
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
Well, I'm making some progress. I didn't need all the jars I had listed in the manifest, I had just put them all there rather than track down all the dependencies (first time using hibernate and it came with all those). I started adding jars one at a time to the 'Class-Path:' line, keeping it on one line, and so far so good. I still have some more jars to add and I haven't figured out why it suddenly stops finding the jars when I try and span them to more than one line.

The app is a standalone app that talks to a MySQL DB, so I don't think the jboss jars are going to be needed. I've been testing on two machines, my dev machine has Java 1.4.2_03 and my laptop has 1.4.2_05. I want to have all the dependencies listed in the Manifest so when I deploy it I don't have to configure the machines, I can just drop in the folder and make a shortcut on the users desktop to the jar.
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Hey, maybe you have it figured out now, but there is some discussion here including about the length.

1. It sounds like the tutorial was wrong, only one entry for Class-path allowed.
2. Sounds like you need 2 spaces at the beginning of a continuation line, not just one.

Discussion about jar manifest class-path

That post is in the sun java forum specifically on jar issues, there might be more suggestions over there.
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
Sweet!! It looks like the two spaces at the beginning of the line did it.

Thanks everybody for your help.
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
Ok, it looks like you have to have two spaces at the beginning of each line (other than the first line that starts with Class-Path , and one space at the end of each line other than the last line. There must also be a return at the end of the last line of the classpath leaving an empty line at the end.

So fricken picky!!

Once again thanks for all the help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Building a jar with dependancies.