This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes possible classpath problem? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "possible classpath problem?" Watch "possible classpath problem?" New topic

possible classpath problem?

Dan Maples
Ranch Hand

Joined: Jun 21, 2004
Posts: 153
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?

Logan Owen

Joined: Dec 01, 2004
Posts: 24
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

Joined: Jun 21, 2004
Posts: 153
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.
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
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.)

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dan Maples
Ranch Hand

Joined: Jun 21, 2004
Posts: 153
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 agree. Here's the link:
subject: possible classpath problem?
jQuery in Action, 3rd edition