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

被折叠的 条评论
为什么被折叠?



