如何强制 Eclipse m2e 插件为项目使用 jdk

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25592290/
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-09-19 21:56:04  来源:igfitidea点击:

How to force Eclipse m2e plugin to use jdk for a project

javaeclipsemavenm2e

提问by Igor Grinfeld

I'm using Maven with 'Eclipse Kepler JavaEE'. I have something like this in 'maven-compiler-plugin' :

我将 Maven 与“Eclipse Kepler JavaEE”一起使用。我在 'maven-compiler-plugin' 中有这样的东西:

<configuration>
    <source>1.7</source>
    <target>1.7</target>
</configuration>

Each time I'm changing somethin in 'pom.xml', eclipse forces me to perform 'Maven -> Update Project' and than project settings are changed to use JRE instead JDK and some maven builds are stopping to work.

每次我更改“pom.xml”中的某些内容时,eclipse 都会强制我执行“Maven -> 更新项目”,然后将项目设置更改为使用 JRE 而不是 JDK,并且一些 Maven 构建停止工作。

The only solution I found to solve it is to set How I can set eclipse/m2e to use JDK is to define a path in maven-compiler-plugin. It is not good solution, since it is working only for my computer will fail for other.

我发现解决它的唯一解决方案是设置 How I can set eclipse/m2e to use JDK 是在 maven-compiler-plugin 中定义路径。这不是一个好的解决方案,因为它仅适用于我的计算机,其他计算机将失败。

I think there are some maven or m2e definitions saying "use jdk and not jre".

我认为有一些 maven 或 m2e 定义说“使用 jdk 而不是 jre”。

回答by Harald Wellmann

In Eclipse, open Window | Preferences | Java | Installed JREs, make sure there's a JDK (and not just a JRE) for Java 1.7, then go to the submenu Execution Environmentsand mark this JDK as compatible with JavaSE-1.7.

在 Eclipse 中,打开Window | 偏好 | 爪哇| 安装 JREs,确保有适用于 Java 1.7 的 JDK(而不仅仅是 JRE),然后转到子菜单Execution Environments并将此 JDK 标记为与 JavaSE-1.7 兼容。

After that, Maven | Update Projectshould work as desired.

之后,Maven | 更新项目应该按需要工作。

回答by Ankur Nirmalkar

First MVN_HOMEhas to be setup and then the JDKas to browsed instead of JRE

首先MVN_HOME必须设置然后JDK浏览而不是JRE

Window--> Preferences--> Java-->Installed JREs

and select JDK(e.g. : jdk1.7 or jdk1.8)

和选择JDK(例如:jdk1.7 or jdk1.8

the do mvn install it will work

do mvn install 它会起作用