编译器错误 - '错误:无法找到或加载主类com.sun.tools.javac.Main' [英] Compiler Error - 'Error: Could not find or load main class com.sun.tools.javac.Main'

查看:967
本文介绍了编译器错误 - '错误:无法找到或加载主类com.sun.tools.javac.Main'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始学习Java,我在我的电脑上安装了JDK,但现在我正在尝试Java的SIMPLIST,而不是编译。我在 C:/ Java / jdk7 / 上安装了JDK。

I just started learning Java and I installed JDK on my computer, but now I am trying the SIMPLIST 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:\Java\jdk7\


b $ b

任何帮助将不胜感激。

Any help would be appreciated!

推荐答案

您可能已经手动安装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


$ b b

此命令应该很好地工作。这类似于您可以使用Java命令的错误,基本上相同的原因,您的安装没有解压缩必要的文件。您可以参考此链接: JRE 1.7返回: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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆