maven build failed: Unable to locate the Javac Com

2020-01-27 10:17发布

I have my JAVA_HOME set to

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

After I run maven install I get this message from eclipse:

Reason:

Unable to locate the Javac Compiler in:
  C:\Program Files (x86)\Java\jre6\..\lib\tools.jar
Please ensure you are using JDK 1.4 or above and
not a JRE (the com.sun.tools.javac.Main class is required).
In most cases you can change the location of your Java
installation by setting the JAVA_HOME environment variable.

I'm certain that this is the tricky part

Please ensure you are using JDK 1.4 or above and not a JRE

When I run configuration its set to JRE6, how do I change it to JDK 1.6 which I have already installed

EDIT

I even tried to modify the plugin :

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.0.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <executable>C:\Program Files (x86)\Java\jdk1.6.0_18\bin</executable>
                </configuration>
            </plugin>

Still I get the same error

Maybe I forgot to say I use eclipse maven plugin .. how can I change from JRE to JDK in eclipse ?

30条回答
家丑人穷心不美
2楼-- · 2020-01-27 10:49
▲ chillily
3楼-- · 2020-01-27 10:51

Eclipse setup only

Do the following steps:

  1. Right Click on Eclipse project Properties

  2. Java Build Path -> Libraries

  3. Select JRE System Library -> Click Edit button

  4. Click "Installed JREs..." button

  5. Edit JRE as: Set JRE Home = JAVA_HOME or JAVA_HOME\jre

ScreentShot:

enter image description here

Many Thanks,

Partha

查看更多
手持菜刀,她持情操
4楼-- · 2020-01-27 10:53

I have just install 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 default jre install 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 don't see anything wrong with my setting. After searching, I decided to look into mvn.bat, I echoed %JAVA_HOME% every step and it displays correctly as C:\java\jdk1.6 but when I run the command : mvn --version, it displays 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%

Hope this helps.

Note: This is for mvn on command line and not with Eclipse.

查看更多
倾城 Initia
5楼-- · 2020-01-27 10:53

I changed the configuration of maven-compiler-plugin to add executable and fork with value true.

            <configuration>
                <fork>true</fork>
                <source>1.6</source>
                <target>1.6</target>
                <executable>C:\Program Files\Java\jdk1.6.0_18\bin\javac</executable>
            </configuration>

It worked for me.

查看更多
对你真心纯属浪费
6楼-- · 2020-01-27 10:55

You try:

Go to Preferences/Java/Installed JREs and add one for the location "C:\Program Files\Java\jdk1.6.0_27\jre or something like that.

Remove the one for C:\Program Files\Java\jre6

As you can see, the path C:\Program Files\Java\jre6\..\lib\tools.jar only makes sense if the first part (til the /..) is replaced by C:\Program Files\Java\jdk1.6.0_27\jre.

查看更多
疯言疯语
7楼-- · 2020-01-27 10:55

I got the same problem using Run as -> Maven install in Eclipse. JAVA_HOME and eclipse.ini were OK and pointing to my latest JDK. But m2clipse used JRE. Using mvn install outside of Eclipse worked fine! In my case I solved the problem as follows: 1. Navigate in Eclipse: Window -> Preferences -> Java -> Installed JREs 2. There were two inactive entries for a JRE and JDK. The active one was the latest installed JDK. Delete all entries but the one maven should use.

I think maven doesn't take into acount which one is active...

查看更多
登录 后发表回答