Forums Register Login

access classfiles outside a jar from inside a jar

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Thank you very much
Not looking good. I think this might be the end. Wait! Is that a tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 751 times.
Similar Threads
Cannot run .jar file
Run jar file
Unable To Run Jar File... Urgent....
How to execute jar file from another directory
Adding jndi.properties to 'Class-Path:' in generated jar file
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 08:16:48.