The problem is probably that your HelloWorld.class file is not on your class path. The class path is the list of one or more directories in which the java application launcher will look for the .class files comprising your application. So, how to specify the class path?

If your program depends only on the J2SE classes, you should not need to use classpath, because those classes are automatically on the classpath. If your program depends on other classes, you need to set classpath to those classes. In that case, it is preferable to use the -classpath option rather than the CLASSPATH environment variable, as the -classpath option enables each application to have its own classpath. For more details, see:

 

Please send questions to the Compiling forum where others can help you.

The following assumes you're running Windows 95/98/NT/2000.

There is a CLASSPATH environment variable. You can see which environment variables are set on your machine by running 'set' at the DOS prompt. If the CLASSPATH variable is set, then its value is your class path. If the CLASSPATH variable is NOT set, then the default class path is the current directory (i.e. whatever directory you run 'java HelloWorld' from).

So if you are trying to run 'java HelloWorld' from the directory in which the HelloWorld.class file is in, and you get the "can't find" error, it's probably an indication that you have the CLASSPATH environment variable set. Try unsetting the CLASSPATH variable: 'set CLASSPATH=' (i.e. setting it to no value is the same as unsetting it). Then try running your application again. Because the CLASSPATH variable isn't set, the class path should default to the correct directory, and your app should launch.

Altenatively, you could set the CLASSPATH environment variable to point to the location of your HelloWorld.class file. However, you'd run into the same "can't find" error if you then tried to run another application located in another directory.

You can also force the class path to be a particular value by using the -classpath option: 'java -classpath C:\myprograms\ HelloWorld'

See class path information in the Java 2 tools documentation for more information.

Posted in: Java

Related FAQ's

Marius Ion ANGEL HOT SOFT LLC (800) 316-7677