• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

possible classpath problem?

 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am setting up my new computer for java, I set the classpath, path, and {JAVA_HOME} all to C:\Program Files\Java\jdk1.5.0\bin. When I compile it works fine, but when I go to run the class files I get this error:

It is just a simple helloword program to try to get things set up, it looks like this:


can anybody help me with this please?
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) obviously your path works, but just to check, go to the command line and type java, make sure that it can find that program.

2) next, you either need to navigate to the directory (chdir) and run it, or put the directory that your class file is in in an enviroment variable called CLASSPATH. This is different then the variable PATH, which is for windows to find its programs.

Hope this helps.
[ December 04, 2004: Message edited by: Logan Owen ]
 
Dan Maples
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
AHHHHHH THANK YOU SOOOO MUCH!!! previously I had tried just typing in "java" and it had worked, so I added the folder it was in to my classpath and it worked, once again thanks so much.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your settings are not correct.

JAVA_HOME should refer to the directory containing the "bin" directory that contains the Java executables "java" and "javac".

JAVA_HOME/bin should be in the PATH so that the operating system can locate the "java" and "javac" executables.

The CLASSPATH is used to locate Java class files (and other resources) needed at compile time and at run time. I don't recommend including JAVA_HOME or JAVA_HOME\bin in your CLASSPATH, because I don't recommend keeping your compiled Java class files in either of these locations. In fact, I recommend not setting the CLASSPATH at all. Unless you're getting into using third party libraries or resources from multiple locations, it's not necessary to have the CLASSPATH set, as the JRE and the Java compiler will automatically find resources in the current working directory. If you are going to set the CLASSPATH, the JRE and the Java compiler will not automatically find resources in the current working directory, and you'll likely want to be sure to include the current working directory, as specified by a period.

In review, if you installed the J2SDK in the "C:\Program Files\Java\jdk1.5.0" directory, I recommend the following settings for your JAVA_HOME, PATH and CLASSPATH environment variables. (Don't forget the quotes since you're using a directory name with a space in it.)

JAVA_HOME="C:\Program Files\Java\jdk1.5.0"
PATH=JAVA_HOME\bin;(Whatever else your system wants.)
Don't set the CLASSPATH. If you must, then include the current working directory, as specified by a period.
CLASSPATH=.;(Whatever else you want.)
 
Dan Maples
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well Dirk, that works too. And if you say this works better, well then I believe that too. so in that case thanks a bunch for helping me get things set up properly.
 
I’m tired of walking, and will rest for a minute and grow some wheels. This is the promise of this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic