javac(和其他 jdk 可执行文件)产生 NoClassDefFoundError
在 Solaris 10 上,我使用 JDK 1.5.0_22,当我运行任何 JDK 可执行文件(javac
、native2ascii
、javadoc
等时)在需要 tools.jar
运行的 JDK/bin 目录中,我收到此错误(带参数和不带参数运行):
线程“main”中出现异常java.lang.NoClassDefFoundError: com/sun/tools/javac/Main
JRE 可执行文件不需要 tools.jar
可以正常工作(java、keytool 等)。
是的,tools.jar
位于 JDK/lib 目录中,权限正常且未损坏 - 我能够查看 tools.jar
的内容并解压他们。
我尝试设置 JAVA_HOME
,并将 JDK/bin 目录添加到 PATH - 设置/取消设置这些环境变量没有区别。我仍然遇到同样的错误。
这是我发现的唯一能够消除 NoClassDefFoundError 并允许 JDK/bin 可执行文件运行的东西(下面的 cmd 是从 JDK/bin 目录运行的):
./native2ascii -J-Xbootclasspath/a:../lib/tools.jar
所以如果我添加 -J-Xbootclasspath/a:../lib/tools.jar
到任何 JDK/bin 可执行文件,例如 javac
、javadoc
、native2ascii< /code>,他们跑了。否则,他们就不会。
关于如何修复有什么想法吗?所有 JDK/bin 可执行文件在我拥有的其他 Solaris 10 系统上都运行良好,并且它们都没有在 PATH 上设置任何 JAVA_HOME
vars 或 JDK/bin。
On Solaris 10, I'm using JDK 1.5.0_22 and when I run any of the JDK executables (javac
, native2ascii
, javadoc
, etc) in the JDK/bin directory that require tools.jar
to run, I get this error (run with and without arguments):
Exception in thread "main" java.lang.NoClassDefFoundError:
com/sun/tools/javac/Main
JRE executables in the bin directory which do not require tools.jar
work fine (java, keytool, etc).
Yes, tools.jar
is located in the JDK/lib directory, and the permissions are OK and it's not corrupt - I am able to view contents of tools.jar
and extract them.
I have tried setting JAVA_HOME
, and adding the JDK/bin directory to PATH - setting/unsetting these environment variables makes no difference. I still get the same error.
This is the only thing I have found that does get rid of the NoClassDefFoundError
and allow the JDK/bin executable to run (cmd below is run from the JDK/bin directory):
./native2ascii -J-Xbootclasspath/a:../lib/tools.jar
So if I add -J-Xbootclasspath/a:../lib/tools.jar
to any JDK/bin executable like javac
, javadoc
, native2ascii
, they run. Otherwise, they do not.
Any ideas on how to fix? All of the JDK/bin executables run fine on other Solaris 10 systems I have, and none of them have any JAVA_HOME
vars set or JDK/bin on the PATH.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果 Java 虚拟机或 ClassLoader 实例尝试加载类的定义(作为普通方法调用的一部分或作为使用 new 表达式创建新实例的一部分)并且没有该类的定义,则会抛出此 NoClassDefFoundError 错误。被发现。
搜索到的类定义在编译当前执行的类时就已存在,但无法再找到该定义。
JAVA_HOME 不应设置为 BIN 文件夹。它应该是这样的上一级:JDK_HOME = C:\Program Files\Java\jdk1.6.0_18
This NoClassDefFoundError is thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.
The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.
The JAVA_HOME should not be set up to the BIN folder. It should be one level up like this:JDK_HOME = C:\Program Files\Java\jdk1.6.0_18