java编译好了无法运行,无法运行简单编译的java程序?

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值