I’ve run into this issue several times now while working on recent Adobe CQ5 projects. The peculiar thing about this problem is that I was only noticing it when trying to do a Maven build in Eclipse. Typically when this error message is seen it means that the Java JDK is not being pointed to correctly. Often what happens is that users will be pointing to a Java JRE instead of the JDK. However, this was not my case and the problem existed solely in Eclipse… let me provide more detail.
The Problem
I was working with a Maven project using the Eclipse IDE. The Maven project was set up correctly, the POM.xml was configured correctly, and my settings.xml file was pointing to the right directory. I was even able to build via commandline:
mvn clean install -e -PautoInstallPackage -Dcrx.port=4502 -Dcrx.host=localhost
However, when I would build the project through eclipse I would get the following error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default -compile) on project core: Fatal error compiling: tools.jar not found: C:Program FilesJavajre6.. libtools.jar -> [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 arti cles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException [ERROR] [ERROR] After correcting the problems, you can resume the build with the command [ERROR] mvn -rf :core
I checked my JAVA_HOME environment variable to make sure that I was pointing correctly to a JDK (as mentioned above). From here, all signs point to Eclipse.
The Resolution
Although it threw me for a loop a couple of times and I side stepped it (mostly because I had a work around with the command line version), the solution was actually quite simple. By default Maven plugin for Eclipse (m2eclipse) does not inherit Java settings from Eclipse and instead inherits them from the POM.xml. If none are provided it will default to Java 1.5. One of the plugins I was using in my Maven project required Java 1.6 or higher.
The solution here was to edit the project specific Java compiler settings in Eclipse. To do this:
- Right click your project in Eclipse and choose “Properties”. You should see a dialog similar to the one below:
- Uncheck the “Use compliance from execution environment” checkbox and change the “Compiler compliance level” drop down to 1.6. When finished your dialog should look similar to the one below:
- Click “Apply” and “Ok” in the dialog. This will force the project to rebuild
After that, perform a Run As -> Maven Install and your project should now be building successfully.
my case, I had to use the JDK instead of JRE in the eclipse java runtimes
Great comment! Mine also worked the same way… using JDK instead of JRE… but do you know what is the issue behind this ? Why JRE is not working ?
Thanks, It works. 🙂
I ran into the same problem and also resolved this problem by adding the JDK to Eclipse’s list of Installed JREs and making it the default. The JRE doesn’t have a lib/tools.jar.
Thank you, it worked. I had to add JDK in my installed JREs and select that path. This post is really helpful.