在Ubuntu中正确设置java classpath和java_home [英] Setting up java classpath and java_home correctly in Ubuntu

查看:344
本文介绍了在Ubuntu中正确设置java classpath和java_home的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到错误


线程main中的异常java.lang.NoClassDefFoundError:

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

当我尝试在Ubuntu上运行编译类时。我使用的是一个非常简单的Helloworld示例,互联网上已有的数百万条响应表明我的CLASSPATH和JAVA_HOME变量设置错误。

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.

但是,我已将etc / environment编辑为正确的文件夹以及当前文件夹:

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

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 /

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

CLASSPATH =。:/ usr / lib / jvm / java-1.5.0-sun / lib

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

当我输入set命令时它们会出现。在任何情况下,即使我使用

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

sudo java -cp . myfirstjavaprog.class

我得到同样的错误。我还应该在哪儿看?这一定是配置问题。

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

非常感谢

推荐答案

你想从最后删除.class。只需输入...

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

java -cp . myfirstjavaprog

这篇关于在Ubuntu中正确设置java classpath和java_home的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆