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条回答
Summer. ? 凉城
2楼-- · 2020-01-27 11:09

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.

查看更多
Anthone
3楼-- · 2020-01-27 11:09

I had the same Error, because of JUNIT version, I had 3 3.8.1 and I have changed to 4.8.1.

so the solution is

you have to go to POM, and make sure that you dependency looks like this

 <dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.8.1</version>
  <scope>test</scope>
</dependency>
查看更多
做自己的国王
4楼-- · 2020-01-27 11:11

Don't forget that if you are running your project from a particular Eclipse configuration, you should change the Java Runtime within 'Run Configurations' --> 'Your maven configuration' --> 'JRE tab'after you add the right JDK to your Eclipse preferences.

查看更多
来,给爷笑一个
5楼-- · 2020-01-27 11:11

Solution to this problem is very simple....

If you don't have ANT build file then generate it. In eclipse you can easily create a ANT file.

Refer to the link to create ANT build file [http://www.codejava.net/ides/eclipse/how-to-create-ant-build-file-for-existing-java-project-in-eclipse].

Now follow the given steps:

1) Add your ANT build file in ANT view that is in view window.

2) right click on your ANT build file and select Run As and the second option in that "Ant Build".

3) Now a dialog box will open with various options and tabs.

4) Select the JRE tab.

5) you will see 3 radio buttons and they will be having JRE or JDK selected as an option.

6) Look carefully if the radio button options are having JRE as selected then change it to JDK.

7) Click apply.

That's it...!!!

查看更多
混吃等死
6楼-- · 2020-01-27 11: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.

查看更多
该账号已被封号
7楼-- · 2020-01-27 11:12

You need to indicate JAVA_HOME in mvn.ini (it's in the maven folder /bin), and your problem will disappear.

查看更多
登录 后发表回答