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

后端 未结 30 2006
长情又很酷
长情又很酷 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: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.

提交回复
热议问题