I have my JAVA_HOME set to:
C:\\Program Files (x86)\\Java\\jdk1.6.0_18
After I run maven ins
Right click on menu Project → Properties → Java Build Path.
Select the JRE System Path → Edit. Select the Workspace Default JRE, and point it to JDK > 1.4.
Go to the Properties dialog and right click on the project.
In Linked resources, add a new path called JAVA_HOME and put in your JDK location, something like "C:\Program Files\Java\jdk1.8.0_73".
That's all!!
I have just installed Maven 3.0.4, set M2_HOME
, M2
and JAVA_HOME
accordingly. I then ran the following commands:
mvn archetype:generate....
mvn compile
I got failed message such as: maven unable to locate javac compiler
.
On my computer, I have by default JRE installed at C:\program files\java\jre.1.6.
And I have the other C:\java\jdk1.6 and JAVA_HOME
set to this C:\java\jdk1.6.
I didn't see anything wrong with my setting. After searching, I decided to look into mvn.bat
, I echoed %JAVA_HOME%
every step and it displayed correctly as C:\java\jdk1.6
, but when I run the command mvn --version
, it displayed Java home: C:\program files\java\jre1.1.6.
Finally, I found out that I just need to set -Djava.home=c:\java\jdk1.6
as in the command below, and working fine now:
%MAVEN_JAVA_EXE% %MAVEN_OPTS% -classpath %CLASSWORLDS_JAR% "-Dclassworlds.conf=%M2_HOME%\bin\m2.conf" "-Djava.home=%JAVA_HOME%" "-Dmaven.home=%M2_HOME%" %CLASSWORLDS_LAUNCHER% %MAVEN_CMD_LINE_ARGS%
Note: This is for mvn
on the command line and not with Eclipse.
I would guess that the location of the compiler is defined in a POM for the compiler plugin to be in the JRE location displayed, instead of the JDK location you have JAVA_HOME pointing to.
I solved the issue by changing location of Installed JRE to the directory present in JDK itself. Setting proper value of JAVA_HOME
environment variable did not solve the issue.
In my case, there are two directories
C:\Program Files\Java\jdk1.7.0_03 --> For JDK
C:\Program Files\Java\jre7 --> For JRE
Initially I set C:\Program Files\Java\jre7
as Installed JRE in Eclipse and I was getting the same error in case of Maven(Ant was working fine).
By changing the installed JRE to C:\Program Files\Java\jdk1.7.0_03\jre7
as Installed JRE in Eclipse the issue is solved.
If you set the JAVA_HOME, and the problem persists try the following.
(I had the same problem, on a fresh installed PC.)
Assuming you are using Eclipse.
That's all. Your project will not suffer from such problems.