This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have David & Dawn Griffiths on-line!
See this thread for details.
Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

access classfiles outside a jar from inside a jar

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 1843
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic