Victor
Victor

Reputation: 1703

Problems running a java program from the command line interface

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

Upvotes: 1

Views: 1076

Answers (3)

wjans
wjans

Reputation: 10115

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

java helloworld.HelloWorld

Also make sure "." is on your classpath.

Upvotes: 1

SJuan76
SJuan76

Reputation: 24780

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.

Upvotes: 1

Harry Joy
Harry Joy

Reputation: 59650

I try to compile it with the command: java HelloWorld

TO compile a java program you should use javac command like

javac Helloworld.java

Upvotes: 1

Related Questions