ubuntu java classpath,在Ubuntu中正确设置java classpath和java_home

本文探讨了在Ubuntu系统中遇到的Java运行错误,重点在于NoClassDefFoundError问题。作者尝试了常见的配置调整,如CLASSPATH和JAVA_HOME设置,并分享了手动设置classpath的方法,但问题依然存在。寻求帮助时,提示可能需要移除.class文件后缀。解决方案可能涉及更深入的系统配置检查。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I am getting the error

Exception in thread "main" java.lang.NoClassDefFoundError:

When I try and run a compiled class on Ubuntu. I am using a very simple Helloworld example, and the millions of responses which already exist on the internet suggest that my CLASSPATH and JAVA_HOME variables have been incorrectly set.

However, I have edited the etc/environment to the correct folders as well as the current folder:

PATH=".:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"

JAVA_HOME="/usr/lib/jvm/java-1.5.0-sun/"

CLASSPATH=".:/usr/lib/jvm/java-1.5.0-sun/lib"

and they appear when I type the set command. In any case, even when I set the classpath manually using

sudo java -cp . myfirstjavaprog.class

I get the same error. Where else should I look? This must be a configuration problem.

Many thanks

解决方案

You want to drop the .class from the end. Just type...

java -cp . myfirstjavaprog

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值