File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Jar Files in another jar file (MANIFEST.MF Question) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Jar Files in another jar file (MANIFEST.MF Question)" Watch "Jar Files in another jar file (MANIFEST.MF Question)" New topic

Jar Files in another jar file (MANIFEST.MF Question)

matt eggbeers

Joined: Mar 11, 2005
Posts: 14
Hey All,
I have a simple soap client written using xfire. It has several jars that it references to other jars. I can run it fine when the directory structure is like this

+- start.bat
+- MyJarFile.jar
+- lib
+- All the referenced jar files

and i use the batch job to add all the jars in /lib to the classpath and it starts great.

My question is, can you add all the third party jars inside the jar file and have tell the manifest file that they are in there? I know you can do it with the jars outside your jar, but what is the syntax of the Class-Path: header in the manifest if the jar is inside the other jar? Well, first off, is this even possible?

matt eggbeers

Joined: Mar 11, 2005
Posts: 14
Sorry, it looks like my dir structure diagram got messed up while posting.

Anyway, I have a dir, test, and in that dir i have a start.bat file, MyJarFile.jar, and a lib dir. In the lib dir are all the third part jars I am using.

sammaiah kyatham
Ranch Hand

Joined: Aug 03, 2003
Posts: 104
Here is the example, try this.

Add the classpath tag inside Manifest.MF as

Class-Path: ../resources/ cuss.jar cussutil.jar utility.jar dom4j.jar
log4j-1.2.8.jar jflash.jar xerces.jar jacorb.jar commons-lang-2.0.jar
xbean.jar PAWSSchema.jar

Let me know if you still have the problem.

[ May 01, 2007: Message edited by: sammaiah kyatham ]
matt eggbeers

Joined: Mar 11, 2005
Posts: 14
First, thanks for the reply. However, I am not sure that you understood my question 100%. The way the you describe, works fine if the lib or resource directory is somewhere OUTSIDE the jar that I am trying to run. What I want to be able to do is package all the needed jars INSIDE one jar file and have the classpath reference the jars inside when trying to execute. I would like to be able to distribute one jar file and one start script and thats it. Is this possible, and if so how?

Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

No. You know how to make it work, you've said that twice. And that's how it is supposed to work.
Jan Cumps

Joined: Dec 20, 2006
Posts: 2565

You could extract classes from all jar files to the same directory, and add your code to that same directory.
Then you can jar that directory.
Read the licenses of the other jar files carefully. You might not be allowed to de-assemble them, or redistribute their classes in another jar.

Still, I think it's better to leave the jars as they are, and distribute them with your application. That's how it's meant to be done: your code in your jars; libraries that you depend upon in their own jars.

Regards, Jan
[ May 01, 2007: Message edited by: Jan Cumps ]

OCUP UML fundamental and ITIL foundation
Alex Luc

Joined: Feb 03, 2006
Posts: 13
I think this can be done.
Check out the Fat Jar Eclipse Plugin (FJEP) and One-Jar
I agree. Here's the link:
subject: Jar Files in another jar file (MANIFEST.MF Question)
It's not a secret anymore!