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?
Try doing
and then, if it comes up with no compiler errors (which it should not do because I cannot see any bugs in your programme), then type
java Hello
Java-File:
then there are two ways of executing it:
See http://scottizu.wordpress.com/2013/08/28/fixing-the-exception-in-thread-main-java-lang-noclassdeffounderror-in-eclipse/.
This is the long form of the Java commands that can be run from a Windows command prompt:
Notice the classpath has no slash at the end. The javac.exe commands expects the file to end with ".java". The java.exe command expects the full class name and does not end with ".class".
There are a few ways to simplify these commands:
You don't have to enter the entire classpath (ie, you can just use -classpath "."). Enter the directory you will be working in:
cd "C:\Users\Scott\workspace\myproject\"
You can use the default package (put the HelloWorld.java file directory in your working directory and don't use the Java package directive)
If you make these changes you would run something like this (and you might be able to leave out -classpath "."):
I had this error because I had my files within a package. So my foo package I had to call like:
java foo.HelloWorld