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

eclipse.ini needs the vm argument to point to your jdk location.

Edit the eclipse.ini file to point to your jdk home, something as follows -

-vm
C:\Program Files\Java\jdk1.6.0_06

This ensures that Eclipse would be running off the JDK and not any default JRE on your machine.

查看更多
等我变得足够好
3楼-- · 2020-01-27 10:58

If you set the JAVA_HOME, and the problem persists try the following. (i had the same problem, on a fresh installed pc.)

Assuming you are using Eclipse.

  • Open Window - preferences - java - installed jre's remove all you have there, add the desired you want to use (JDK, no JRE!)
  • In the same window open maven - installations, add the mave installation you downloaded and extracted somewhere. (DO NOT USE the embedded maven installation, it has some known bugs)

Thats all. your project will not suffer from sutch problems. Hope helps.

查看更多
家丑人穷心不美
4楼-- · 2020-01-27 10:59

As mentioned by several others, the Eclipse Window->Preferences...->Java->Installed JREs should point to the JDK you installed, not to the JRE. Only then it can find the ../lib folder mentioned in the error message.

Even with this, the problem may recur. My way out in Eclipse (Juno) is to do a Maven -> Update project... after which the problem disappears.

I suspect the reason is that some of the Eclipse generated files (.classpath, .project, .preferences) are in subversion for the project in which I'm having these problems. Thus, an svn update introduces the problem, and an configuration update from maven in Eclipse resolves it again.

Real solution: omit Eclipse generated .files from version control, and let the maven eclipse plugin handle project configuration. (additional pointers/suggestions welcome).

查看更多
叛逆
5楼-- · 2020-01-27 11:01

I had EXACT the same problem! Been searching and searching for days because all the babble about "put the -vm c:\program files\java\jdkxxxxx\bin" in the ini ar as argument for a shortcurt did NOT AT ALL heklp! (Do I sound frustrated? Believe me, that's an understatement! I am simply furious because I lost a week trying to make Maven reliable!)

I had very unpredictable behavior. Sometimes it compiled, sometimes not. If I did a maven clean, it could not find the compiler and failed. If I then changed something in the build path, it suddenly worked again!!

Until I went to window -> preferences -> java -> installed JRE's. I added a new JRE using the location of the JDK and then removed the JRE. Suddenly maven ran stable!

Maybe this is worth putting in letters with font-size 30 or so in the apache manual? With all due respect, this is simply outrageous for the java community! I can't imagine how many days were lost by all these people, trying to work out their problems of this kind! I cannot possibly imagine this is released as a final version. I personally would not even dare to release such a thing under the name BETA software...

Kind regards either way.... After a week of tampering I can finally start developing. I hope my boss won't find out about this. It took me lots of effort to convince him NOT to go to .NET and I already feel sorry about it.

查看更多
6楼-- · 2020-01-27 11:04

Make sure the "-vm" in your eclipse.ini is on two sperate lines, ie:

-vm
C:\Program Files\Java\jdk1.6.0_06
查看更多
SAY GOODBYE
7楼-- · 2020-01-27 11:05

In my case, in eclipse Run-> Debug Configurations In the jre tab selected the jdk instead of the jre solved the problem.

查看更多
登录 后发表回答