Java Notes
CLASSPATH
[an error occurred while processing this directive]Do you get the following error message?
Exception in thread "main" java.lang.NoSuchMethodError: main
If so, the following are common causes.
- File/class name mismatch. Check the file and class names -- they much match exactly, even with upper and lower case. Windows doesn't care about file names that differ only in case, but Java does. If you have trouble renaming a file to fix the case, first rename it to something different, then rename to the correct case.
- Typo in
mainheader. Something is wrong with your declaration ofmain. It must bepublic static void main(String[] args)Slight variations in the parameter declaration are allowed, but the above is by far the most common. - CLASSPATH is explained below in more detail.
CLASSPATH tells Java where to search for programs
Where to look? The Java runtime system needs to know where to find programs that you want to run and libraries that are needed. It knows where the predefined Java packages are, but if you are using additional packages, you must tell specify where they are located.
CLASSPATH. For Windows the easiest way is to set the environment variable CLASSPATH, which Java uses to see where it should find Java programs and libraries.
Automatic? Some IDEs tell the Java runtime system where to search, and double-clickable Jar (Java Archive) files don't have this problem
When do you need it? If you compile "by hand"
(typing javac and java in a command window),
or sometimes with TextPad or other editors.
Setting CLASSPATH on Windows XP
The CLASSPATH variable can be set on Windows XP with the following steps.- Click the
Startbutton in the lower left of the screen. - Select
Control Panelfrom the pop-up menu. - Choose
Systemfrom the submenu. - Click the
Advancedtab. - Click the
Environment Variablesbutton near the bottom and you will see two lists of variables. - Look in the
System variableslist for a variable namedCLASSPATH. If you find it, clickEdit. If you don't find it, clickNewand enterCLASSPATHin theVariable namefield. -
The
Variable valuefield is a list of file paths of directories orjarfiles. The first thing in this list should be the current directory, which is represented in windows just as it is in Unix, as a single period. If there's more than one thing in this list, separate items with a semicolon. For example, my CLASSPATH variable starts with these three items (there are a couple more, but this should be enough to give you the idea). The only part you need is the first "dot"..;C:\classpath\com.fredswartz.ezgui.jar;c:\classpath\TableLayout.jar;I put extra libraries that I want to be searched in a directory namedclasspath, but you can choose any name.
References
A more complete explanation ofCLASSPATH can be found in
Java Glossary : classpath.















