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?
The
CLASSPATH
variable needs to include the directory where your Java programs .class file is. You can include '.' inCLASSPATH
to indicate that the current directory should be included.If you want to 'compile and execute' any java file that you have created using any IDE(like eclipse), just run the below commands:
if your Program.java is in "src/mypkg/subpkg/" directory:
go to "src" dir
Then to compile use "javac mypkg/subpkg/Program.java"
To run use "java mypkg.subpkg.Program.class"
Your
CLASSPATH
needs to know of the location of yourHelloWorld
class also.In simple terms you should append dot
.
(means current directory) in theCLASSPATH
if you are runningjavac
andjava
commands from DOS prompt.Run it like this:
I had the same problem, and stumbled onto a solution with 'Build Main Project F11'. The ide brought up an "option" that I might want to uncheck 'Compile on Save' in the Build > Compiling portion of the Project configuration dialog. Unchecking 'Complile on Save' and then doing the usual (for me) 'Clean and Build' did the trick for me.