File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

access classfiles outside a jar from inside a jar

 
tormod eriksen
Ranch Hand
Posts: 52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1824
Eclipse IDE Java Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Carl Trusiak
Sheriff
Posts: 3340
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
tormod eriksen
Ranch Hand
Posts: 52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic