wilbeibi
wilbeibi

Reputation: 3454

Java works fine in Eclipse, but cannot run normally in Terminal

Environment: Ubuntu 12.04, JRE 1.6.0

In my zsh, even a simple hello.java cannot run normally. It's ok when compiled it with javac, but then typed java hello:

Exception in thread "main" java.lang.NoClassDefFoundError: hello
Caused by: java.lang.ClassNotFoundException: hello
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: hello.  Program will exit.

Upvotes: 0

Views: 264

Answers (3)

PSR
PSR

Reputation: 40318

The class name is helloworld and you are trying to say java hello. Check it once

Upvotes: 0

Sam P
Sam P

Reputation: 453

Try java helloworld. By default, Java will compile with the same name as the file.

so javac helloworld.java outputs helloworld.class, which is what you need to access to run the bytecode.

Upvotes: 0

sanbhat
sanbhat

Reputation: 17622

Your class name seems to be helloworld and you are trying to say java hello

(hence JVM tries to find a class named hello which doesnt exist)

please try java -classpath . helloworld

Upvotes: 4

Related Questions