Maven Could not find the Javac compiler in:

When I try to create a war file, it shows 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 refers to jre when my environment variable is jdk. I also changed the installed JRE to jdk1.6.

+73
java maven javac
Sep 25
source share
17 answers

Only in Eclipse setup

It has 4 steps todo.

Step 1: Right Click on the Eclipse Project Project

Step 2: Java Build Path → Libraries

Step 3: Select the JRE System Library → Click the "Change" button → Click "Installed JREs ..."

Step 4: edit the JRE as Set JRE Home = JAVA_HOME

ScreentShot:

enter image description here

+150
Mar 20 '13 at 9:53 on
source share

Go to window → Settings ... → Java → Installed JRE

Change JRE Home = JAVA_HOME or JAVA_HOME \ jre

For example, if you are using jdk1.6.0_04, which is installed in C: \ Program Files, make the following changes:

C: \ Program Files \ Java \ jdk1.6.0_04 \ jre or C: \ Program Files \ Java \ jdk1.6.0_04 instead of the standard file, which is located in the folder C: \ Program Files \ Java \ jre7

+35
Dec 21 '12 at 16:55
source share

Had the same problem, but in my case, a directory eclipse indicated that the JRE was a JDK. So, I searched for this tools.jar and was there.

I did

  • Java Build Path → Libraries
  • JRE Librari System → Edit
  • Installed JRE -> click on my jdk -> edit
  • Add external jars → tools.jar

And then compiled thin

+4
Jul 25 '13 at 15:09
source share

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

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

Having determined, correct your path

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

This was an Eclipse issue. When I tried to build it from the command line using

 mvn package 

It worked fine.

+3
Sep 25
source share

It looks 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 such as ...;%JDK_HOME% .

Make sure the path %JDK_HOME%\bin is in your PATH variable is unresolved even if you need to explicitly specify the path.

+2
Sep 25
source share

I had the same error, due to the JUNIT version I had 3 3.8.1 and I changed to 4.8.1.

therefore the solution

you need to go to POM and make sure you depend on how it looks

  <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.1</version> <scope>test</scope> </dependency> 
+2
01 Oct '13 at 9:27
source share

I tried all the above suggestions that did not help me, but I found how to fix the error in my case.

The following steps allowed you to successfully compile the project:

In the project explorer, right-click the project and select Properties. In the tree on the right, navigate to the Java build path. Select the "libraries" tab. Click Add Library. Select the JRE system library. Click Next. Select the Alternate JRE switch. Click Installed JRE. Select the JRE with the correct version. Click Appy and close. On the next screen, click Finish. In the properties window, click Apply and close. In the project explorer, right-click your file pom.xml and select “Run as”> “Build Maven.” In the target text box, type “install.” Click Run.

This made the project successful in my case.

+1
Jan 04 '19 at 12:22
source share

In Eclipse, actions such as importing Maven projects or calling the "Update Sources" are performed in the same JVM in which Eclipse is running. If this JVM comes from a JRE that is not part of the JDK, there would be no Java compiler (tools.jar).

So, in order to start Maven from Eclipse, the JRE used to start it must also come from the JDK. By default, Eclipse registers the JRE, it starts, but it can be configured on the preferences page "Window / Preferences ... / Java / Installed JREs", as mentioned above, Parthasarathy

Alternatively, you can specify compilerId in pom.xml, so Maven will not look for the 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> 
0
Apr 09 '14 at 4:35
source share

I ran into a similar problem, and since no one has posted an approach similar to mine, here I go.

Go to the launch configuration you want to run.
There the JRE tab was selected. Adjust the "Runtime JRE" there, and you are ready to go.

0
May 28 '14 at 7:18
source share

I can solve by following these steps:

Right-click on the project, select Build Path → Configure Build Path → select the “Libraries” tab → then select the JRE System Library [version you have JavaSE-1.7 for me] → click the “Edit” button → “In the JRE System” Library window Select a runtime. In the drop-down list, you can select the JDK specified for me, its JavaSE-1.7 → next to this click, to the button “Environment” → In the window “Run windows” you should select your java SE again for me, its JavaSE-1.7 → just select it, you will have options on the Compatible JREs tab, so select the JDK that you want to have in my case its jdk1.7.0_25.




Click OK and complete the remaining windows by completing the appropriate Ok / Finish steps.

Finally, do Maven Clean and Maven Install.

0
Jul 22 '15 at 14:29
source share

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

0
Jul 05 '16 at 20:42 on
source share

If you follow all the above steps that may be confusing, and our problem is only in the absence of tools.jre, just add tools.jre by following the steps below and the problem will be solved.

Step 1: In Eclipse, go to Windows -> Settings

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

Step 3: Click Modify → Click Add External JAR Files

Step 4. Now select the tools.jar path

Now apply the changes and they work great.

Here is a screenshot

0
Mar 17 '18 at 6:46
source share

Although there are several answers that are not related to Eclipse above, to this question that do not mention Eclipse, they require changing path variables. An alternative is to use the command line parameter, java.home, for example:

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

Pay attention to \ jre at the end - an amazing necessity.

0
Jun 30 '18 at 19:21
source share

None of the current answers helped me here. We got 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 is because the Java installation has determined that it is a JRE installation. It is assumed that there will be a JDK above the JRE subdirectory, hence ../lib in the path. Our tools.jar is located in $JAVA_HOME/lib/tools.jar , not in $JAVA_HOME/../lib/tools.jar .

Unfortunately, we have no way to install JDK in our OS (do not ask), so this was not possible. I fixed the problem by adding the following to 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 directing the executable to the right place, we at least overcame our compilation errors.

0
Aug 15 '19 at 22:22
source share

For others encountering this problem in Eclipse, even with the correct JDK path, you need to remove the other JREs from the installed JREs.

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

.Select unused JREs individually and delete

It worked for me.

0
Sep 21 '19 at 7:22
source share

For Intellij Idea, install everything correctly (similar to this):

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

and don’t forget to restart Idea . This program captures variables at startup, so any changes to environment variables while the program is running will have no effect.

-one
Sep 04 '15 at 8:36
source share



All Articles