java.lang.ClassNotFoundException
The ClassNotFoundException occurs when a java application is trying to load a class that is not on the 'classpath'.
There are several ways to set the classpath for your JAVA application.
Compile and run from command line
When compiling and executing your application from the command line using javac.exe and java.exe, use the classpath argument:
cd \applicationdirectory
javac.exe -classpath . HelloWorld.java
java.exe -classpath . HelloWorld
The '.' indicates that all classes that are in the active directory should be added to the classpath.
If you also have classes that have to be found on other locations, add them to the argument seperated by a ';' like this:
javac.exe -classpath .;C:\anotherdirectory HelloWorld.java
Compile and run using TextPad
If you are using TextPad to write your first java program (as I did when I wrote my first HelloWorld program), this menu will be quite familiar:
To configure the 'classpath' in TextPad you go to Configure > Preferences...
Set the classpath using the parameters field:
Compile and run using an IDE (like Eclipse, NetBeans, Borland, ... )
Each IDE provides a way to set the classpath. Have a look at the documentation of your IDE or 'google' for the IDE name in combination with 'classpath'.
Set CLASSPATH system environment variable
Indepandantly of how you compile and run your program, this approach wil always work. However, only use this approach during development and testing.
Create a System environment variable that is called 'CLASSPATH'.
Set the directories that contain the classfiles seperated by a ';'. Restart your system.
