简体   繁体   中英

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.

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 java -classpath . helloworld

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM