[java] Maven Unable to locate the Javac Compiler in:

When i try to generate a war file, it is showing some error like

[ERROR] Unable to locate the Javac Compiler in:
[ERROR] C:\Program Files\Java\jre7\..\lib\tools.jar

When i do echo %path% it shows

 C:\Windows\System32;D:\name\name1\Softwares\Maven\apache-maven-3.0.4\b
in;C:\Program Files\Notepad++\;%JDK_HOME%

When i do echo %JDK_HOME%

D:\name\name\core java\software\Java\Java_1.6.0_04_win\jdk1.6.0_04\bin

I don't know why maven is refering to jre, when my environmental variable is jdk. I also changes installed JRE to jdk1.6.

This question is related to java maven javac

The answer is


Had the same problem, but in my case, the directory eclipse pointed the JRE was the JDK. So, i searched for that tools.jar and was there.

I did

  • Java Build Path >> Libraries
  • JRE System Lybrary >> Edit
  • Installed JREs >> click on my jdk >> edit
  • Add External Jars >> tools.jar

And then compiled fine


It depends on of Maven version. When you will install newer version of Maven, this error would not appear. You may also add another directory with tools.jar file lib/tools.jar - it also solve this problem.


I have encountered a similar problem, and as no one posted an approach similar to mine, here I go.

Navigate to the run configuration you wanted to launch.
There chose the JRE tab. Adjust the "Runtime JRE" there, and you're ready to go.


Its in Eclipse setup only

It has 4 steps TODO.

Step 1 : Right Click on Eclipse project Properties

Step 2 : Java Build Path -> Libraries

Step 3 : Select JRE System Library -> Click Edit button -> Click Installed JREs... button

Step 4 : Edit JRE as Set JRE Home = JAVA_HOME

ScreentShot:

enter image description here


I tried all of the above suggestions, which did not work for me, but I found how to fix the error in my case.

The following steps made the project compile succesfully:

In project explorer, right-click on project, select “properties” In the tree on the right, go to Java build path. Select the tab “libraries”. Click “Add library”. Select JRE system library. Click next. Select radio button Alternate JRE. Click “installed JRE’s”. Select the JRE with the right version. Click Appy and close. In the next screen, click finish. In the properties window, click Apply and close. In the project explorer, right-click your pom.xml and select run as > maven build In the goal textbox, write “install”. Click Run.

This made the project build succesfully in my case.


I had the same Error, because of JUNIT version, I had 3 3.8.1 and I have changed to 4.8.1.

so the solution is

you have to go to POM, and make sure that you dependency looks like this

 <dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.8.1</version>
  <scope>test</scope>
</dependency>

For Intellij Idea set everything appropriately (similarly to this):

JAVA_HOME = C:\Program Files\Java\jdk1.8.0_60
JRE_HOME = JAVA_HOME\jre

and dont forget to restart Idea. This program picks up variables at start so any changes to environtment variables while the program is running will not have any effect.


Though there are a few non-Eclipse answers above for this question that does not mention Eclipse, they require path variable changes. An alternative is to use the command line option, java.home, e.g.:

mvn package -Djava.home="C:\Program Files\Java\jdk1.8.0_161\jre"

Notice the \jre at the end - a surprising necessity.


It sounds like you have JDK_HOME defined as a user variable and PATH defined as a System variable, or vice versa - echo %PATH% should not contain unresolved variables like ...;%JDK_HOME%.

Make sure that the %JDK_HOME%\bin path is on your PATH variable, unresolved, even if you have to put the path in explicitly.


None of the current answers helped me here. We were getting something like:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:
    #.#.#:compile (default-compile) on project Streaming_Test: Compilation failure
[ERROR] Unable to locate the Javac Compiler in:
[ERROR] /opt/java/J7.0/../lib/tools.jar

This happens because the Java installation has determined that it is a JRE installation. It's expecting there to be JDK stuff above the JRE subdirectory, hence the ../lib in the path. Our tools.jar is in $JAVA_HOME/lib/tools.jar not in $JAVA_HOME/../lib/tools.jar.

Unfortunately, we do not have an option to install a JDK on our OS (don't ask) so that wasn't an option. I fixed the problem by adding the following to the maven pom.xml:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
      <fork>true</fork>  <!-- not sure if this is also needed -->
      <executable>${JAVA_HOME}/bin/javac</executable>
      <!--        ^^^^^^^^^^^^^^^^^^^^^^ -->
    </configuration>
  </plugin>

By pointing the executable to the right place this at least got past our compilation failures.


I am able to resolved by doing following steps :

Right click on project select Build path -> Configure build path -> select Libraries Tab -> then select JRE System Library[version you have for me its JavaSE-1.7] - > click Edit button -> In JRE System Library window select Execution environment - In drop down you can select the JDK listed for me its JavaSE-1.7 -> next to this click to Environments button -> In Execution Environments window you have to again select your java SE for me its JavaSE-1.7 -> just select it, you will have options in Compatible JREs tab, so select JDK that you want to have in my case its jdk1.7.0_25.


Click ok and finish the rest windows by doing appropriate action Ok/Finish.

Lastly do Maven Clean and Maven Install.


Go to Window -> Preferences... -> Java -> Installed JREs

Edit JRE Home = JAVA_HOME or JAVA_HOME\jre

For example if you use jdk1.6.0_04 which is installed in C:\Program Files, do the following change:

C:\Program Files\Java\jdk1.6.0_04\jre or C:\Program Files\Java\jdk1.6.0_04 instead of the default one which is at C:\Program Files\Java\jre7


If you we are doing all above steps that may be confused and our problem is just missing tools.jre so just add tools.jre by the following steps and problem is solved.

Step 1 : In eclipse go to Windows -> preferences

Step 2 : Java -> Installed JREs (Double click on it)

Step 3 : Click Edit button -> Click Add External JARs

Step 4 : Now select tools.jar path

now apply changes and it works fine.

Here is screenshoot


The JDK_HOME variable should always point to the base dir of the jdk, not the bin dir:

D:\name\name\core java\software\Java\Java_1.6.0_04_win\jdk1.6.0_04

That defined, fix your path to be

C:\Windows\System32;D:\name\name1\Softwares\Maven\apache-maven-3.0.4\bin;C:\Program Files\Notepad++\;%JDK_HOME%\bin

In Eclipse, actions like importing Maven projects or invoking "Update Sources" runs in the same JVM in which Eclipse is running. If that JVM comes from JRE that isn’t part of JDK, there would be no Java compiler (the tools.jar).

So to launch Maven from within Eclipse, JRE used for launch also need to come from JDK. By default Eclipse registers JRE it is started in, but this can be configured on "Window / Preferences… / Java / Installed JREs" preference page as mentioned above by Parthasarathy

Alternatively you can specify compilerId in the pom.xml, so Maven won’t be looking for JDK when compiling Java code:

 <plugin>
  <artifactid>maven-compiler-plugin</artifactid>
  <configuration>
    <compilerid>eclipse</compilerid>
  </configuration>
  <dependencies>
    <dependency>
      <groupid>org.codehaus.plexus</groupid>
      <artifactid>plexus-compiler-eclipse</artifactid>
      <version>xxxx</version>
    </dependency>
  </dependencies>
</plugin>

For others facing this issue in Eclipse even with path set to JDK correctly, you need to remove the other JREs from Installed JREs.

Go to Window -> Preferences -> Java -> Installed JREs

Select unused JREs individually and Remove

It worked for me.


It was an Eclipse problem. When I tried to build it from the command line using

mvn package

it worked fine.


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to maven

Maven dependencies are failing with a 501 error Why am I getting Unknown error in line 1 of pom.xml? Why am I getting "Received fatal alert: protocol_version" or "peer not authenticated" from Maven Central? How to resolve Unable to load authentication plugin 'caching_sha2_password' issue Unable to compile simple Java 10 / Java 11 project with Maven ERROR Source option 1.5 is no longer supported. Use 1.6 or later 'react-scripts' is not recognized as an internal or external command How to create a Java / Maven project that works in Visual Studio Code? "The POM for ... is missing, no dependency information available" even though it exists in Maven Repository Java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/exc/InvalidDefinitionException

Examples related to javac

Setting up enviromental variables in Windows 10 to use java and javac "Javac" doesn't work correctly on Windows 10 Error:java: invalid source release: 8 in Intellij. What does it mean? Javac is not found Maven Unable to locate the Javac Compiler in: Unable to locate an executable at "/usr/bin/java/bin/java" (-1) javac is not recognized as an internal or external command, operable program or batch file javac option to compile all java files under a given directory recursively Creating a batch file, for simple javac and java command execution javac : command not found