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

查看:25
本文介绍了在 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天全站免登陆