编译器错误 - “错误:无法找到或加载主类 com.sun.tools.javac.Main" [英] Compiler Error - 'Error: Could not find or load main class com.sun.tools.javac.Main'
问题描述
我刚开始学习 Java 并在我的计算机上安装了 JDK,但现在我正在尝试最简单的 Java 并且它没有编译.我在 C:/Java/jdk7/
上安装了 JDK.
I just started learning Java and I installed JDK on my computer, but now I am trying the SIMPLEST of Java and its not compiling. I installed JDK on C:/Java/jdk7/
.
每当我尝试编译时,都会出现错误:
Whenever I try to compile, I get an error:
Error: Could not find or load main class com.sun.tools.javac.Main
这是我的编译方式:
javac test.java
我也试过:
javac.exe test.java
我不知道我的代码是否有问题,但这是我的test.java
:
I don't know if my code is wrong or anything, but here is my test.java
:
class test {
public static void main(String args[]) {
System.out.println("Hello World!");
}
}
这里是 JAVA_HOME:
Here is JAVA_HOME:
C:Javajdk7
任何帮助将不胜感激!
推荐答案
您可能已经手动安装了 JDK.无论如何,这个错误几乎肯定是由于您的 Java 安装中的缺陷造成的.为了解决它,您必须在您的 JAVA_HOME/lib 目录中执行以下命令:
You probably have done a manual installation of JDK. Anyway, this error is almost certainly due to a flaw in your Java installation. In order to solve it, you must execute the following command in your JAVA_HOME/lib directory:
unpack200 -r -v -l "" tools.pack tools.jar
unpack200 -r -v -l "" tools.pack tools.jar
这将解压 tools.jar 文件,这是您的安装(手动或非手动)没有为您完成的.之后尝试执行:
This will unpack the tools.jar file, which your installation (manual or not) had not done for you. After that try to execute:
javac -version
javac -version
这个命令应该可以正常工作.这类似于您使用 Java 命令可能遇到的错误,出于基本相同的原因,您的安装没有解压必要的文件.可以参考这个链接:JRE 1.7 返回:java/lang/NoClassDefFoundError:java/lang/Object
This command should work well. This is similar to the error you can have with the Java command, for basically the same reason, your installation didn't unpack necessary files. You can refer to this link: JRE 1.7 returns: java/lang/NoClassDefFoundError: java/lang/Object
我自己也遇到了这个问题,我的解决方案是对另一个答案的一些改编.
I had this problem myself and my solution is a little adaptation of this other answer.
这篇关于编译器错误 - “错误:无法找到或加载主类 com.sun.tools.javac.Main"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!