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 access classfiles outside a jar from inside a jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "access classfiles outside a jar from inside a jar" Watch "access classfiles outside a jar from inside a jar" New topic
Author

access classfiles outside a jar from inside a jar

tormod eriksen
Ranch Hand

Joined: Jan 23, 2002
Posts: 52
I want to access classfiles libraries on the system from inside my jarfile application (Windows NT). It seems I automatically have access to the java runtime, no matter what the classpath variable is like, but I haven't succeeded in getting access to my other classfile libraries. If unpack my jarfile and then run the application I have access, but not if I run the application directly from the jarfile (by doubleclicking or writing java -jar <name of jar>.
I get java.lang.ClassNotFoundException
Any ideas to help?
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

Running from an executable jar is a different thing from running from nat a jar in that, when you run from the jar file, the CLASSPATH environment variable is ignored (as you found out).
To solve this problem, include the following entry in you manifest file:
Class-Path: <directory1> <directory2> <directory3>

Note the spelling and hyphenation of "Class-Path". Also note that the path entries are separated by spaces and not by ; (or : ) Also, these directories are relative to the location of the jar file, not the directory from which you run the "java" command.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
This is definately a Classpath issue. RunnningJars with the -jar option, the Classpath is Automatically : your java lib directory, the current directory and the Jar you are running! Not your system Classpath variable!!!
There are two ways to set the classpath for -jar, one is to include the -cp on the command line (Not likely you can use this with double click to start)
The second is to include the entry "Class-Path :" in your Manifest file. Details on this can be found at http://java.sun.com/j2se/1.4.1/docs/guide/jar/jar.html#Main%20Attributes


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
tormod eriksen
Ranch Hand

Joined: Jan 23, 2002
Posts: 52
Thank you very much
 
wood burning stoves
 
subject: access classfiles outside a jar from inside a jar
 
Similar Threads
Adding jndi.properties to 'Class-Path:' in generated jar file
How to execute jar file from another directory
Run jar file
Unable To Run Jar File... Urgent....
Cannot run .jar file