Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
545 views
in Technique[技术] by (71.8m points)

java - Compiler Error - 'Error: Could not find or load main class com.sun.tools.javac.Main'

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

Here is how I'm compiling:

javac test.java

I also tried:

javac.exe 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!");
    }
}

Here is JAVA_HOME:

C:Javajdk7

Any help would be appreciated!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...