Maven build failed: “Unable to locate the Javac Compiler in: jre or jdk issue”

后端 未结 30 1990
长情又很酷
长情又很酷 2020-11-30 20:33

I have my JAVA_HOME set to:

C:\\Program Files (x86)\\Java\\jdk1.6.0_18

After I run maven ins

相关标签:
30条回答
  • 2020-11-30 21:10

    Right click on menu ProjectPropertiesJava Build Path.

    Select the JRE System Path → Edit. Select the Workspace Default JRE, and point it to JDK > 1.4.

    0 讨论(0)
  • 2020-11-30 21:10

    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!!

    0 讨论(0)
  • 2020-11-30 21:11

    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.

    0 讨论(0)
  • 2020-11-30 21:11

    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.

    0 讨论(0)
  • 2020-11-30 21:12

    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.

    0 讨论(0)
  • 2020-11-30 21:12

    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.

    • Open WindowPreferencesJavaInstalled jre's. Remove all you have there, add the desired you want to use (JDK, no JRE!)
    • In the same window open maven - installations, add the Maven installation you downloaded and extracted somewhere. (Do not use the embedded Maven installation. It has some known bugs.)

    That's all. Your project will not suffer from such problems.

    0 讨论(0)
提交回复
热议问题