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:45

Setting Fork to true resolved the issue for me.

<configuration>
<fork>true</fork>
<source>1.6</source>
<target>1.6</target>
</configuration>

Thank you very much, Sam Yang..you made my day

查看更多
Deceive 欺骗
3楼-- · 2020-01-27 10:45

You can also make sure that Eclipse has all of the updated changes. To do this, right-click your project and then press the "Refresh" menu item.

查看更多
Ridiculous、
4楼-- · 2020-01-27 10:46

Right click on Project -> Properties -> Java Build Path. Select the JRE System Path -> Edit. Select the Workspace Default JRE, and point it to JDK > 1.4

查看更多
可以哭但决不认输i
5楼-- · 2020-01-27 10:46

Window -> Preferences -> Java -> installed JREs -> Execution Enviroments -> click the checkbox on the right side

查看更多
疯言疯语
6楼-- · 2020-01-27 10:46

do Echo %JAVA_HOME%
then mvn --version

JRE path should be same.... then go Window -> preferences - java - installed jre's
location should be same as what Java_Home is showing.

查看更多
我命由我不由天
7楼-- · 2020-01-27 10:47

It sounds like Maven is using the JRE, not the JDK. Perhaps you installed Maven before installing the JDK?

Check the settings files. There are 3 in total, system, user, and project. Its most likely in the installation config ($M2_HOME/conf/settings.xml) or, possibly, the per-user config (${user.dir}/.m2/settings.xml).

查看更多
登录 后发表回答