Error Messages on Microsoft Windows Systems
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp
If you receive this error, java cannot find your bytecode file, HelloWorldApp.class.
One of the places java tries to find your .class file is your current directory. So if your .class file is in C:\java, you should change your current directory to that. To change your directory, type the following command at the prompt and press Enter:
The prompt should change to C:\java>. If you enter dir at the prompt, you should see your .java and .class files. Now enter java HelloWorldApp again.
If you still have problems, you might have to change your CLASSPATH variable. To see if this is necessary, try clobbering the classpath with the following command.
Now enter java HelloWorldApp again. If the program works now, you'll have to change your CLASSPATH variable. To set this variable, consult the Update the PATH variable section in the JDK 6 installation instructions.
Αυτά λέει μέσα στο tutorial...5. Update the PATH variable (Optional)
You can run the JDK without setting the PATH variable, or you can optionally set it as a convenience.
Should I set the PATH variable?
Set the PATH variable if you want to be able to conveniently run the JDK executables (javac.exe, java.exe, javadoc.exe, etc.) from any directory without having to type the full path of the command. If you don't set the PATH variable, you need to specify the full path to the executable every time you run it, such as:
C:> "\Program Files\Java\jdk1.6.0_<version>\bin\javac" MyClass.java
It's useful to set the PATH permanently so it will persist after rebooting.
How do I set the PATH permanently?
To set the PATH permanently, add the full path of the jdk1.6.0_<version>\bin directory to the PATH variable. Typically this full path looks something like C:\Program Files\Java\jdk1.6.0_<version>\bin. Set the PATH as follows, according to whether you are on Microsoft Windows NT or 98/2000/ME.
Microsoft Windows NT, 2000, and XP - To set the PATH permanently:
1. Choose Start, Settings, Control Panel, and double-click System. On Microsoft Windows NT, select the Environment tab; on Microsoft Windows 2000 select the Advanced tab and then Environment Variables. Look for "Path" in the User Variables and System Variables. If you're not sure where to add the path, add it to the right end of the "Path" in the User Variables. A typical value for PATH is:
Capitalization doesn't matter. Click "Set", "OK" or "Apply".
The PATH can be a series of directories separated by semi-colons (;). Microsoft Windows looks for programs in the PATH directories in order, from left to right. You should only have one bin directory for a JDK in the path at a time (those following the first are ignored), so if one is already present, you can update it to jdk1.6.0_<version>\bin.
2. The new path takes effect in each new Command Prompt window you open after setting the PATH variable.
The CLASSPATH variable is set in the same manner.