aspose file tools*
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
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
Author

Refering a jar file from another jar

Sahil Sharma
Ranch Hand

Joined: Aug 27, 2003
Posts: 152
Hi,

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.

Manifest.mf file contents.

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

Thanks
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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 ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Refering a jar file from another jar