Issue: The following problem occurs when I compile my project w/ maven (note: I'm working on windows):
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project XYZ: Fatal error compiling: tools.jar not found: C:\java\jdk1.8.0_40..\lib\tools.jar -> [Help 1]
Error occurs from both command line and eclipse (Eclipse STS) - mvn clean; mvn install
Notes:
This is because by default Apache Maven will use the Maven Compiler Plugin plugin to compile the code, which will use the JDK tools.jar library, but the default JRE in Eclipse will not contain this library. So what is the solution to fix this error? I would like to guide you as follows: On the Eclipse menu, go to Window -> Preferences.
Plugin Goals The compiler plugin is used to compile the source code of a Maven project. This plugin has two goals, which are already bound to specific phases of the default lifecycle: compile – compile main source files
By default, the compiler plugin compiles source code compatible with Java 5, and the generated classes also work with Java 5 regardless of the JDK in use. We can modify these settings in the configuration element: For convenience, we can set the Java version as properties of the POM: Sometimes we want to pass arguments to the javac compiler.
If tools.jar is not found, try adding it up in your project's dependencies on eclipse. Firstly, copy the location of tools.jar which would look something like this C:\Program Files\Java\jdk1.x.x\lib Then, on eclipse, Right click your project and go to Properties -> Java Build Path -> Libraries Click on ADD External JARs button.
Issue resolved: Setting System env variable, JAVA_HOME, to Java JDK 1.7 fixed the problem.
I tried jdk1.7.0_45 and jdk1.7.0_75 - they both worked.
Notes:
I also faced similar issue when building the project in eclipse ( sts version) I figured out the issue was because I had jre installed in 2 locations and I jre configured in the eclipse was pointing to the pure jre folder. So just check that your jre is pointing to the jre folder inside the jdk not any other jre as the tools.jar is in jdk/lib
Even after configuring Eclipse to use a JDK from Window -> Preferences -> Java -> Installed JRES, you may still get errors when you try to perform a Maven build.
In this case make sure that the JRE tab in Maven Build is configured correctly.
Go to Run -> Run Configurations, open the Maven Build category and do one of the following:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With