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

Problem. The following problem occurs when compiling my w / maven project (note: I'm working on windows):

The target org.apache.maven.plugins failed: Maven-compiler-plugin: 2.5.1: compile (default compilation) in the XYZ project: fatal error compilation: tools.jar not found: C: \ java \ jdk1.8.0 _40 .. \ lib \ tools.jar → [Help 1]

The error occurs both from the command line and from the eclipse (Eclipse STS) - mvn clean; mvn install

Notes:

  • The env system variable, JAVA_HOME, was set to C: \ java \ jdk1.8.0_40
  • C: \ java \ jdk1.8.0_40 \ lib \ tools.jar is
  • Tried to clean local maven repository (.m2) - error still occurred
  • configured maven compiler plugin to point to C: /java/jdk1.7.0_75/bin/javac.exe executable with source = target = 1.7 - same error
  • I tried installing java 1.7.0_75 in eclipse and using this (but maven is still used for compilation - right-click on the project, run as, maven install): the same error (even with the executable configuration file of the maven compiler, C: / java / jdk1.7.0_75 / bin / javac.exe)
+5
source share
6 answers

Problem resolved: Installing System env variable, JAVA_HOME, on Java JDK 1.7 fixed the problem.

I tried jdk1.7.0_45 and jdk1.7.0_75 - they both worked.

Notes:

  • I thought that you need to install the compiler executable for the compiler plugin in pom.xml means that the executable was used in all cases; apparently this is not so: the JAVA_HOME variable overrides it in this case.
  • Some other people had problems with B / C, their JAVA_HOME was set to JRE instead of JDK. My JAVA_HOME for Java 1.8 was installed in JDK 1.8, but I still got the same error.
+9
source

I also encountered a similar problem when creating a project in eclipse (sts version) I realized that the problem is that I installed jre in 2 places and I configured in eclipse, pointing to the pure jre folder. So just check that your jre points to the jre folder inside jdk and not to another jre as tools.jar is in jdk / lib

+5
source

If tools.jar is not found, try adding it depending on the project in eclipse.

First, copy the location of tools.jar, which will look something like this: C: \ Program Files \ Java \ jdk1.xx \ lib

Then, on the eclipse, right-click your project and go to Properties → Java Build Path → Libraries

Press the ADD External JARs button .

Paste the link that you copied above into the File Name link bar and click OK.

Now tools.jar should be specified in libraries.

Click "OK" to close the window.

Now run the installation of Maven.

It worked for me.

+1
source

Make sure Eclipse points to the JDK and not the JRE. To do this: Window ==> Preferences ==> Java ==> Installed JRES ==> Add button ==> Standard virtual machine and add JDK path.

0
source

When I added the JDK to the libraries, the problem was resolved. The problem is that tools.jar was not found as part of the jre distribution

0
source

Make sure Eclipse points to the JDK, not the JRE. To do this: Window ==> Settings ==> Java ==> Installed JRES ==> Add button ==> Standard virtual machine and add your JDK path. It worked.

0
source

Source: https://habr.com/ru/post/1216003/


All Articles