The following program is throwing error:
public class HelloWorld {
public static void main(String args[]) {
System.out.println("Hello World!");
}
}
CLASSPATH C:\Program Files\Java\jdk1.6.0_18\bin\
Path C:\Program Files\Java\jdk1.6.0_18\bin\
JAVAHOME C:\Program Files\Java\jdk1.6.0_18\bin
Can you please tell me the root cause?
I finally found this as a bug with Apache Netbeans editor:
Below steps will remove the error:
Hope that helps, if you are using new Apache Netbeans (not old Netbeans)
I found one another common reason. If you create the java file inside a package using IDE like eclipse, you will find the package name on the top of your java file like "package pkgName". If you try to run this file from command prompt, you will get the NoClassDefFoundError error. Remove the package name from the java file and use the commands in the command prompt. Wasted 3 hours for this. -- Abhi
I spent four hours trying various permutations & search suggestions.
At last, found this post that worked but not the best solution to change the original code to test it.
set classpath=JDKbin;JDKlib;JREbin;JRElib;myClassLib;.
java <packageName>.<className>
also tried thejava ..\<packageName>.<className>
Neither worked.
However first response alone worked. Thank you so much Abhi!!!
Curious if there is any other way to make it work without having to change the original code? Thank you!
Here is what finally worked.
One of the places java tries to find your
.class
file is your current directory. So if your.class
file is inC:\java
, you should change your current directory to that.To change your directory, type the following command at the prompt and press Enter:
This
.
tells java that your classpath is your local directory.type the following in the cmd prompt, within your folder: