[英]Java works fine in Eclipse, but cannot run normally in Terminal
Environment: Ubuntu 12.04, JRE 1.6.0 环境:Ubuntu 12.04,JRE 1.6.0
In my zsh, even a simple hello.java
cannot run normally. 在我的zsh中,即使是简单的hello.java
也无法正常运行。 It's ok when compiled it with javac
, but then typed java hello
: 用javac
编译可以,但是键入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
您的班级名称似乎是helloworld
并且您正在尝试说java hello
(hence JVM tries to find a class named hello
which doesnt exist) (因此,JVM试图找到一个不存在的名为hello
的类)
please try java -classpath . helloworld
请尝试java -classpath . helloworld
java -classpath . helloworld
The class name is helloworld
and you are trying to say java hello
. 该类的名称是helloworld
,您正在尝试说java hello
。 Check it once 检查一次
Try java helloworld. 试试java helloworld。 By default, Java will compile with the same name as the file. 默认情况下,Java将使用与文件相同的名称进行编译。
so javac helloworld.java outputs helloworld.class, which is what you need to access to run the bytecode. 因此javac helloworld.java输出helloworld.class,这是运行字节码所需的访问权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.