Maven Unable to locate the Javac Compiler in:
Asked Answered
D

19

76

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.

Dominations answered 25/9, 2012 at 14:42 Comment(2)
The JDK_HOME should be the base directory, i.e. without the \bin and you should have %JDK_HOME%\bin in your path. Can you run D:\name\name\core java\software\Java\Java_1.6.0_04_win\jdk1.6.0_04\bin\java -version ?Lori
Maven expects JAVA_HOME to be set to your JDK installation directory, not JDK_HOME. See Maven installation instructions.Physical
E
153

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

Ema answered 20/3, 2013 at 9:53 Comment(3)
i got the same problem and i have done as you shown here... and now its working fine,,, but i am wondering how come till now it was worked fine without this change (setting up java home to jre).for me my project worked fine till now but suddenly i got this error when i re run my project in eclipse.Ibex
@Preeth :Ultimately your eclipse might have mapped JDK. if you have had removed JDK or updated you got this problemEma
Eclipse often references to JRE outside the JDK. You should change the path to JDK/jre. It works for me.Colleencollege
O
36

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

Odessa answered 21/12, 2012 at 16:55 Comment(2)
It works if you're using eclipse (run as maven build..) But this error got solved by setting the java_home environment variable. Anyway, thanks for your answer sir, it worked for me on eclipse.Divebomb
This worked for me, but wow - SO annoying after setting every single possible JAVA_HOME, JDK_HOME, JRE_HOME etc to my jdk (or jdk/jre) loccation.Dishwater
R
6

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

Remote answered 25/7, 2013 at 15:9 Comment(0)
T
3

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
Telfer answered 25/9, 2012 at 14:49 Comment(0)
D
3

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

mvn package

it worked fine.

Dominations answered 25/9, 2012 at 15:46 Comment(0)
G
2

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.

Garbers answered 25/9, 2012 at 14:46 Comment(0)
C
2

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>
Cimabue answered 1/10, 2013 at 9:27 Comment(0)
H
2

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.

Hudibrastic answered 21/9, 2019 at 7:22 Comment(0)
L
1

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.

Leto answered 4/1, 2019 at 12:22 Comment(0)
M
0

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>
Matter answered 9/4, 2014 at 4:35 Comment(0)
R
0

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.

Rezzani answered 28/5, 2014 at 7:18 Comment(0)
C
0

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.

Capuche answered 22/7, 2015 at 14:29 Comment(1)
This answer would be better if it said which application you're using. :)Fragile
N
0

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.

Norvol answered 5/7, 2016 at 20:42 Comment(0)
E
0

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

Ensiform answered 17/3, 2018 at 6:46 Comment(0)
D
0

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.

Dree answered 30/6, 2018 at 19:21 Comment(0)
P
0

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.

Pell answered 15/8, 2019 at 22:22 Comment(0)
C
0

Make sure mvn is configured to use the correct jre . mvn uses the jre that belongs to the JDK set as your JAVA_HOME try the mvn -version command and make sure that runtime has the value {JAVA_HOME}\jre

Crossbeam answered 5/5, 2022 at 17:30 Comment(0)
V
0

Try to change your Run configuration :

Eclipse \ Run \ Run configurations \ Maven Build \ <your run configuration> \ JRE \ try to set up a jdk*

Varices answered 19/7, 2023 at 10:45 Comment(0)
E
-1

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.

Essayist answered 4/9, 2015 at 8:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.