Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to locate the Javac Compiler when compiling with maven - Unable to locate the Javac Compiler in:

I have compilation error on compiling with maven.

[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] Unable to locate the Javac Compiler in:
  C:\Program Files\Java\jre1.6.0_05\..\lib\tools.jar

So I set JAVA_HOME environment variable but no advantage. The error seems maven search java compiler in jre path, not in JAVA_HOME.

  • JAVA_HOME is C:\Program Files\Java\jdk1.6.0_05.

  • Installed JRE is C:\Program Files\Java\jre1.6.0_05.

  • My PATH variable is:

C:\Program Files\PC Connectivity Solution\;D:\alfrescoplatform\ImageMagick;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\Wbem;C:\Program Files\ImageMagick-6.7.3-Q16;C:\Program Files\Java\jdk1.6.0_05\bin

Here is my detail log

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building SpringMVC Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ SpringMVC ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ SpringMVC ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 2 source files to D:\Learning\spring-workspace\SpringMVC2.5.6\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] Unable to locate the Javac Compiler in:
  C:\Program Files\Java\jre1.6.0_05\..\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.
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.719s
[INFO] Finished at: Thu Nov 01 17:22:43 MMT 2012
[INFO] Final Memory: 4M/8M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project SpringMVC: Compilation failure
[ERROR] Unable to locate the Javac Compiler in:
[ERROR] C:\Program Files\Java\jre1.6.0_05\..\lib\tools.jar
[ERROR] Please ensure you are using JDK 1.4 or above and
[ERROR] not a JRE (the com.sun.tools.javac.Main class is required).
[ERROR] In most cases you can change the location of your Java
[ERROR] installation by setting the JAVA_HOME environment variable.
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

If you have any idea about this, let me know.

like image 510
swemon Avatar asked Nov 12 '22 18:11

swemon


1 Answers

Your JAVA_HOME is C:\Program Files\Java\jdk1.6.0_05

Way 1: The following steps would work for Eclipse:

  1. Go to Window -> Preferences -> Java -> installed JREs
  2. Edit the existing JRE location as: Set JRE Home = JAVA_HOME or JAVA_HOME\jre (In your case the path should be C:\Program Files\Java\jdk1.6.0_05 OR C:\Program Files\Java\jdk1.6.0_05\jre)
  3. Click Finish and OK button

Way 2: Another way to set the JRE System Library:

  1. Open eclipse and Right click on Eclipse project Properties
  2. Java Build Path -> Libraries
  3. Select JRE System Library -> Click Edit button
  4. Click "Installed JREs..." button
  5. Edit JRE as: Set JRE Home = JAVA_HOME or JAVA_HOME\jre

Way 3: The following steps should also work well:

  1. Go to Window -> Preferences -> Java -> installed JREs
  2. Select the JRE you are using
  3. Press Edit -> Add External JARs...
  4. Browse to Java\jdk1.6.0_05\lib and select tools.jar and Press Enter
  5. Click Finish and OK button
like image 178
Ripon Al Wasim Avatar answered Nov 15 '22 08:11

Ripon Al Wasim