Problems running a java program from the command line interface
I created a java program in Eclipse. When 开发者_如何学GoI run the program in Eclipse ("run as -> Java Application") the program runs fine and I have the correct output. However, when I try to run the program in the command line interface I got this error:
Exception in thread "main"
java.lang.NoClassDefFoundError
:HelloWorld
(wrong name: helloworld/HelloWorld) Could not find the main class: HelloWorld. Program will exit.
The class file is in directory bin and I try to run it with the command:
java HelloWorld
Since your class is in the package helloworld
you should run it like this:
java helloworld.HelloWorld
Also make sure "." is on your classpath.
I try to compile it with the command: java HelloWorld
TO compile a java program you should use javac command like
javac Helloworld.java
Are you sure that the directory where your classes are is in the classpath? Typically, in your project directory, the "classes" or "lib" directory.
If you are running from that directory, you could try adding ".".
See the -cp parameter of java runtime executable.
精彩评论