Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven in Eclipse complains that "Unable to locate the Javac Compiler" whenever POM changed

Tags:

I got error message every time I changed my pom.xml in eclipse.

Build errors for myapp; org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project web: Compilation failure
Unable to locate the Javac Compiler in:
  C:\Program Files (x86)\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

I have set JAVA_HOME environment variable. It is:JAVA_HOME=D:\Java\jdk1.6.0_23

Thanks.

like image 554
Tom Avatar asked Mar 02 '11 03:03

Tom


People also ask

Does Eclipse use Javac?

Eclipse has its own built-in incremental compiler so it does not need (nor use) javac from a JDK. So yes, Eclipse's Java Development Tools (JDT) will function with only a JRE.


4 Answers

This is the step I did to solve that problem (Eclipse 3.7 Indigo):

Window -> Preferences -> Java -> installed JREs -> I have a JRE from the JDK location, my location looks like C:\Program Files\Java\jdk1.6.0_26

Window -> Preferences -> Java -> installed JREs -> Execution Environments -> Select JavaSE-1.6 and select a compatible JDK which should be the one set in the previous step.

like image 83
Sydney Avatar answered Sep 20 '22 03:09

Sydney


None of the above worked for me but when I followed the following steps, the problem went away.

  • Go to Window -> Preferences -> Java -> installed JREs
  • Select the JRE you are using (Should be the one inside jdk. Ex: C:\Program Files\Java\jdk1.6.0_25\jre)
  • Press Edit -> Add External JARs...
  • Browse to Java\jdk1.6.0_25\lib and select tools.jar and Press Enter
  • Press Finish and OK
like image 27
isuru chathuranga Avatar answered Sep 18 '22 03:09

isuru chathuranga


Window -> Preferences -> Java -> installed JREs -> Execution Enviroments -> click the checkbox on the right side

like image 36
Gambotic Avatar answered Sep 21 '22 03:09

Gambotic


I had this same issue which I just figured out. The Runtime JRE was specified correctly in EVERY other part of eclipse.

I use an eclipse Run Configuration...

The Run Configuration is YET ANOTHER place where the java runtime JRE is specified. If you are using a maven Run Configuration, open that up, click the JRE tab and select the proper (JDK) "Runtime JRE".

like image 22
april26 Avatar answered Sep 20 '22 03:09

april26