在Ubuntu中正确设置java classpath和java_home

在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