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 11:05

I had the same issue on Amazon Linux. Turns out I had to install the devel version of the jdk:

sudo yum -y install java-1.7.0-openjdk-devel

查看更多
贪生不怕死
3楼-- · 2020-01-27 11:05

Many other answers tell you to point your Eclipse to a JDK instead of a JRE.

Here is another answer with more specific/clear [than I have seen in any answer here] step-by-steps on how to do that: How do you install JDK?

That is what for solved me for this same problem.

查看更多
Emotional °昔
4楼-- · 2020-01-27 11:07

Go to the Eclipse Window->Preferences...->Java->Installed JREs should point to the JDK you installed, not to the JRE.

查看更多
Luminary・发光体
5楼-- · 2020-01-27 11:07

Go to the Properties making right click on the project.

In LINKED RESOURCES add a new Path called JAVA_HOME and put your jdk location, something like "C:\Program Files\Java\jdk1.8.0_73"

That's all!!

查看更多
Evening l夕情丶
6楼-- · 2020-01-27 11:08

The solution is simple, some times the eclipse windows -> preference -> java -> Installed JREs pointing to C:\Program files\Java\jre, when i changed it to C:\Program files\Java\JDK 6.0\jre it is working 100%.

查看更多
仙女界的扛把子
7楼-- · 2020-01-27 11:09

You could try updating the JDK Eclipse is using, as follows:

Add and set the JRE in Window->Preferences...->Java->Installed JREs:

JRE type: Standard VM JRE 
Name: jdk1.6.0_18
JRE home directory: C:\Program Files (x86)\Java\jdk1.6.0_18

If this is not the case, it's possible that the brackets and spaces in the JAVA_HOME path are causing issues. Try copying your JDK to a different location and updating your JAVA_HOME.

查看更多
登录 后发表回答