1

I created a java program in Eclipse. When I 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
skaffman
  • 398,947
  • 96
  • 818
  • 769
Victor
  • 1,655
  • 9
  • 26
  • 38

3 Answers3

1

I try to compile it with the command: java HelloWorld

TO compile a java program you should use javac command like

javac Helloworld.java
Harry Joy
  • 58,650
  • 30
  • 162
  • 207
1

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.

SJuan76
  • 24,532
  • 6
  • 47
  • 87
1

Since your class is in the package helloworld you should run it like this:

java helloworld.HelloWorld

Also make sure "." is on your classpath.

wjans
  • 10,009
  • 5
  • 32
  • 43