Exception in thread "main" java.lang.NoClassDefFoundError: Atest
Caused by: java.lang.ClassNotFoundException: Atest
at java.security.AccessController.doPrivileged(Native Method)
Could not find the main class: Atest. Program will exit.
Volume in drive C has no label.
Volume Serial Number is 4449-5A9A
Directory of C:\JAVA\lib
11/19/2010 11:40 AM <DIR> .
11/19/2010 11:40 AM <DIR> ..
09/24/2010 02:05 PM <DIR> asjava
11/19/2010 11:39 AM 14,817,259 ct.sym
11/19/2010 11:39 AM 145,442 dt.jar
11/19/2010 11:39 AM 218,066 htmlconverter.jar
11/19/2010 11:39 AM 18,396 ir.idl
11/19/2010 11:39 AM 1,692 jawt.lib
11/19/2010 11:39 AM 388,074 jconsole.jar
11/19/2010 11:39 AM 296,524 jvm.lib
11/19/2010 11:39 AM 429 orb.idl
11/19/2010 11:40 AM 12,636,184 tools.jar
11/19/2010 11:40 AM <DIR> visualvm
9 File(s) 28,522,066 bytes
4 Dir(s) 58,107,191,296 bytes free
You forgot to add the current directory to the classpath. Without it, the JVM can't find the class file that the java compiler just created.
It is best to not set your CLASSPATH environment variable at all. So, delete the variable. Note that you need to close and re-open the Windows command prompt after deleting the variable.
If you need to specify a classpath (for example, because you need to include JAR files), it's best to do so on the command line, using the "-cp" switch. you should also include the current directory "." if you do that. For example:
javac -cp SomeLibrary.jar;. MyProgram.java
java -cp SomeLibrary.jar;. MyProgram
So, is there a more better way to structure a project that includes another persons classes? Is it best practice to put them into in my current working directory? I was attempting to isolate them into a common shared location (c:\java\lib, probably not the best choice after all).
Also, when is it proper to set the CLASSPATH environment variable, if ever, and use it instead of using the command line options at compile/run time?
Thanks again, I appreciate your help!
Gil Steidle wrote:So, is there a more better way to structure a project that includes another persons classes? Is it best practice to put them into in my current working directory? I was attempting to isolate them into a common shared location (c:\java\lib, probably not the best choice after all).
Don't put your source code or other files in the JDK installation directory (or a subdirectory). You don't want to mess up the JDK directory with your own files. Put them in a separate directory somewhere.
If you start a project and need to organise your source code, compiled classes etc. then at some point you don't want to manage all of that manually. There are tools like Ant and Maven to manage your project directory and the build process. You could also use an IDE such as NetBeans or Eclipse, that will manage all of this for you.