maven build failed: Unable to locate the Javac Compiler in: jre or jdk issue

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2222560/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 04:53:10  来源:igfitidea点击:

maven build failed: Unable to locate the Javac Compiler in: jre or jdk issue

javaeclipsemaven

提问by Gandalf StormCrow

I have my JAVA_HOME set to

我的 JAVA_HOME 设置为

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

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

运行 maven install 后,我从 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

请确保您使用的是 JDK 1.4 或更高版本而不是 JRE

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

当我将配置设置为 JRE6 时,如何将其更改为我已经安装的 JDK 1.6

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 ?

也许我忘了说我使用 eclipse maven 插件..如何在 eclipse 中从 JRE 更改为 JDK?

采纳答案by lucrussell

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

您可以尝试更新 Eclipse 正在使用的 JDK,如下所示:

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

在 Window->Preferences...->Java->Installed JREs 中添加并设置 JRE:

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.

如果不是这种情况,则 JAVA_HOME 路径中的括号和空格可能会导致问题。尝试将您的 JDK 复制到其他位置并更新您的 JAVA_HOME。

回答by Robin

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.

我猜编译器的位置是在 pom 中定义的,编译器插件位于显示的 jre 位置,而不是您 JAVA_HOME 指向的 jdk 位置。

回答by Devon_C_Miller

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

听起来 Maven 使用的是 JRE,而不是 JDK。也许您在安装 JDK 之前安装了 Maven?

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).

检查设置文件。总共有3个,系统、用户和项目。它最有可能在安装配置 ($M2_HOME/conf/settings.xml) 或每个用户的配置 (${user.dir}/.m2/settings.xml) 中。

回答by Markus

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.

我在 Eclipse 中使用 Run as -> Maven install 遇到了同样的问题。JAVA_HOME 和 eclipse.ini 没问题,指向我最新的 JDK。但是 m2clipse 使用了 JRE。在 Eclipse 之外使用 mvn install 工作正常!就我而言,我按如下方式解决了问题: 1. 在 Eclipse 中导航:Window -> Preferences -> Java -> Installed JREs 2. JRE 和 JDK 有两个非活动条目。活动的是最新安装的JDK。删除所有条目,但 maven 应该使用。

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

我认为 maven 没有考虑哪个是活跃的......

回答by Lorenzo

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!)

我有完全相同的问题!一直在搜索和搜索几天,因为所有关于“将 -vm c:\program files\java\jdkxxxxx\bin”放在 ini ar 中作为快捷方式的参数的所有胡言乱语根本没有heklp!(我听起来很沮丧吗?相信我,那是轻描淡写!我很生气,因为我花了一周时间试图让 Maven 变得可靠!)

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!!

我有非常不可预测的行为。有时编译,有时不编译。如果我做了一个 Maven 清理,它就找不到编译器并且失败了。如果我随后更改了构建路径中的某些内容,它会突然再次起作用!!

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!

直到我转到窗口 -> 首选项 -> java -> 安装 JRE。我使用 JDK 的位置添加了一个新的 JRE,然后删除了 JRE。突然maven跑稳了!

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...

也许这值得在 apache 手册中放入字体大小为 30 左右的字母?恕我直言,这对 Java 社区来说简直是太离谱了!我无法想象所有这些人浪费了多少天,试图解决他们这种问题!我无法想象这是作为最终版本发布的。我个人甚至不敢以BETA软件的名义发布这样的东西......

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.

无论哪种方式,亲切的问候......经过一周的篡改后,我终于可以开始开发了。我希望我的老板不会发现这件事。我花了很多努力来说服他不要去 .NET,我已经为此感到抱歉。

回答by asHIS

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

右键单击项目 -> 属性 -> Java 构建路径。选择 JRE 系统路径 -> 编辑。选择 Workspace Default JRE,并将其指向 JDK > 1.4

回答by Sam Yang

回答by Sai Hegde

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

eclipse.ini 需要 vm 参数来指向您的 jdk 位置。

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

编辑eclipse.ini文件以指向您的 jdk home,内容如下 -

-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.

这可确保 Eclipse 将运行在 JDK 之外,而不是您机器上的任何默认 JRE。

回答by Gambotic

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

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

回答by Prash

Setting Fork to true resolved the issue for me.

将 Fork 设置为 true 为我解决了这个问题。

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

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

非常感谢,Sam Yang..你让我开心