无法运行简单编译的java程序? [英] Cannot run simple compiled java program?
问题描述
我在Arch Linux上,我刚刚安装了JRE和JDK,所有正确的bin文件(javac和java)都在/ opt / java / bin /
我只是编译一个标准的hello世界,并用运行 javac ./hello.java
的javac编译它,并创建了一个类。
现在我的问题是运行它。我运行java ./helloworld.class,它给我一个错误,即使我指向java的文件是不存在的:
线程main中的异常java.lang.NoClassDefFoundError:// helloworld / class
原因:java.lang.ClassNotFoundException:..helloworld.class
(为了清楚起见...)
找不到主类:./helloworld.class。程序将退出。
你会注意到错误的第一行,它将路径 / helloworld / class
当我喂java的绝对路径,即 java /home/foo/helloworld.class
它给出相同的错误,但在第一行中替换路径的 /
与。
,再次变得模糊。
你觉得怎么样?我真的不知道为什么它这样做..
当你运行java,你只是传递完全限定
java helloworld
会查找helloworld.class。 / p>
java helloworld.class
将查找helloworld / class.class
I am on Arch Linux, I just installed JRE and JDK and all the proper bin files (javac and java) are in /opt/java/bin/
I simply compiled a standard hello world, and compiled it with javac running javac ./hello.java
and that made a class.
Now my problem is running it. I run java ./helloworld.class and it gives me an error, even if the file I point java to is non-existant:
Exception in thread "main" java.lang.NoClassDefFoundError: //helloworld/class
Caused by: java.lang.ClassNotFoundException: ..helloworld.class
(..omitted for clarity..)
Could not find the main class: ./helloworld.class. Program will exit.
You will notice the first line of the error, it munges the path //helloworld/class
When I feed java an absolute path, i.e java /home/foo/helloworld.class
it gives the same error, but replaces the path's /
with .
in the first line, again munged.
What do you think is wrong? I really don't know why it is doing this..
When you run java, you just pass it the fully qualified class name (including package), not the file name.
java helloworld
will look for helloworld.class.
java helloworld.class
will look for helloworld/class.class
这篇关于无法运行简单编译的java程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!