Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven Unable to locate the Javac Compiler in:

Tags:

java

maven

javac

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.

like image 487
BKK Avatar asked Sep 25 '12 14:09

BKK


9 Answers

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

like image 181
Parthasarathy B Avatar answered Oct 13 '22 19:10

Parthasarathy B


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

like image 25
Pradeep Vairamani Avatar answered Oct 13 '22 19:10

Pradeep Vairamani


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

like image 41
Hinotori Avatar answered Oct 13 '22 19:10

Hinotori


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
like image 30
Bruno Penteado Avatar answered Oct 13 '22 21:10

Bruno Penteado


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

mvn package

it worked fine.

like image 28
BKK Avatar answered Oct 13 '22 19:10

BKK


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.

like image 21
matt b Avatar answered Oct 13 '22 21:10

matt b


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>
like image 36
Ibo Avatar answered Oct 13 '22 21:10

Ibo


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.

like image 35
HeXMaN Avatar answered Oct 13 '22 20:10

HeXMaN


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.

like image 27
FunkyFeudalFox Avatar answered Oct 13 '22 20:10

FunkyFeudalFox