Bill Metazone
Bill Metazone

Reputation: 171

Fatal error compiling: tools.jar not found - maven-compiler-plugin

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:

Upvotes: 6

Views: 40074

Answers (8)

Rajashekar
Rajashekar

Reputation: 1

I don't know whether this will help or not, I had a similar type of issue:

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\jre1.8.0_271..\lib\tools.jar -> [Help 1].

So I searched for tools.jar in jdk/lib and found it. I copied it from jdk lib to jre lib folder. I restarted my sts and it worked fine.

Upvotes: 0

nkatsar
nkatsar

Reputation: 1670

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:

  1. Make sure that the Workspace default JRE is selected and it points to a JDK.
  2. In the Alternate JRE menu, select a configured JDK.

Run Configurations screenshot

Upvotes: 2

KiwiFlys
KiwiFlys

Reputation: 5

Make sure if Eclipse is pointing to a JDK and Not a JRE. For that : Window ==> Preferences ==> Java ==> Installed JRES ==> Add button ==> Standard VM and add your JDK path . This worked.

Upvotes: 0

Santhosh V
Santhosh V

Reputation: 85

When I added the JDK to the Libraries the problem was solved. The issue is like tools.jar is not found as part of the jre distribution

Upvotes: 0

Sofiane Majdoub
Sofiane Majdoub

Reputation: 886

Make sure if Eclipse is pointing to a JDK and Not a JRE. For that : Window ==> Preferences ==> Java ==> Installed JRES ==> Add button ==> Standard VM and add your JDK path .

Upvotes: 0

Vijayaraghavan
Vijayaraghavan

Reputation: 11

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.

Paste the link you have copied above on File Name link bar and click OK button.

Now, tools.jar should be listed on Libraries.

Click okay to close the window.

Now, run the Maven install.

This worked for me.

Upvotes: 1

Liju John
Liju John

Reputation: 1896

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

Upvotes: 5

Bill Metazone
Bill Metazone

Reputation: 171

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 thought setting the compiler executable for the compiler plugin in pom.xml would mean that the executable was used in all cases;
    apparently it's not - the JAVA_HOME variable overrode it in this
    case.
  • Some other folks had issues b/c their JAVA_HOME was set to a JRE instead of a JDK. My JAVA_HOME for Java 1.8 was set to JDK 1.8, but I still received the same error.

Upvotes: 9

Related Questions