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

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.


Did you reboot after you installed? There are some important environment variables (namely the CLASSPATH) that aren't set until you reboot Windows. Anyway, you can work around it by adding rt.jar and tools.jar to your CLASSPATH. Also, you should probably make sure your JAVA_HOME is set.