Friday, August 26, 2011

[Maven] maven-compiler-plugin: ERROR Unable to locate the Javac Compiler in: C:\Program Files\Java\jre6\..\lib\tools.jar


If you’ve installed Maven plugin for Eclipse and while trying to build/install through Run -> Maven Install, you’re getting following error:

[ERROR] Unable to locate the Javac Compiler in:
  C:\Program Files\Java\jre6\..\lib\tools.jar
Please ensure you are using JDK 1.4 or above and
not a JRE (the com.sun.tools.javac.Main class is required).
In most cases you can change the location of your Java
installation by setting the JAVA_HOME environment variable.

Here is the simplest solution to this most annoying problem:

Go to Window -> Preferences -> Java -> Installed JREs
  1. Remove the default jre
     
  2. Add new JRE location pointing to C:\Program Files\Java\jdk1.6.0_26\jre i.e. same as of your JAVA_HOME\jre
Click ok and try running your project through Maven Install.
Enjoy :)