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 Refering a jar file from another 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 "Refering a jar file from another jar" Watch "Refering a jar file from another jar" New topic

Refering a jar file from another jar

Sahil Sharma
Ranch Hand

Joined: Aug 27, 2003
Posts: 152

I have one jar file that needs to refer some of the files from xerces.jar.
I know that we cannot include a jar within a jar.
The other way is to have a manifest file. But the problem I am facing while using the manifest file is when I place both the jar in same folders than everything works but if i put them in different folders or drives (D:some.jar and c:xerces.jar) than I get classnotfound exception.
Can someone please tell me how should I refer a jar from another jar. file contents.

Manifest-Version: 1.0
Class-Path: xercesImpl.jar

Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

The Class-Path entry in the manifest should contain the path of the referred-to jar file relative to the jar file that contains the manifest.

So, if you go to the command line and change your current directory to the directory where your executable jar file is, then typing "dir" followed by whatever is in the Class-Path entry should show you that referred-to jar.

However my preference would be to put the referred-to jars in the same directory as the executable jar. Makes things much simpler. If you were planning to keep things like Xerces in a standard directory and have all your executable jars refer to that, I think that's false economy. Besides which it isn't a practical strategy if you're going to distribute the executable jar along with all its dependencies.
[ March 05, 2008: Message edited by: Paul Clapham ]
I agree. Here's the link:
subject: Refering a jar file from another jar
It's not a secret anymore!