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

Running jar from anywhere

Ben Johnson
Greenhorn

Joined: Aug 15, 2006
Posts: 4
Hi folks,

I've recently put an executable jar file together which is dependant on several other jar files. When I create the executable jar file I ammend the classpath in the manifest to include those libraries,

i.e. Class-Path: ./lib/jasperreports-1.2.3.jar ./lib/log4j-1.2.13.jar

these references are obviously relative to the location of the executable jar file. If I then run the executable jar file from its own directory everything works fine. However, if I run it from another directory the classpath obviously points to the wrong location, and nothing works.

How do I set the classpath so that it's relative to the executable jar file no matter where I run it from?

The reason I want to know is that I'm planning to execute the jar from a cgi file, however the cgi file could be located anywhere.

Thanks
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8708
    
    6

The easiest thing to do would be to unjar all the third party jars, combine with your class files and make one large jar.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Tim LeMaster
Ranch Hand

Joined: Aug 31, 2006
Posts: 226
I think the easiest thing to do is add them to the MANIFEST.MF file. Jars listed in MANIFEST.MF are relative to the location of the jar containing it.


[ October 16, 2006: Message edited by: Tim LeMaster ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Running jar from anywhere
 
Similar Threads
Junilu, Ian, Peter and others pls help
Executable java file
why can't I execute .jar file this way.
access classfiles outside a jar from inside a jar
Using a directory inside of a JAR file