[英]Eclipse project: Maven Eclipse Plugin set wrong JRE class path container
I have an Eclipse Mars 2 Java8, Maven 3.5.4 based workspace. 我有一个基于Eclipse Mars 2 Java8,Maven 3.5.4的工作区。 I build the project files with
mvn eclipse:clean eclipse:eclipse
, and watch the following maven output: 我使用
mvn eclipse:clean eclipse:eclipse
构建项目文件,并观看以下maven输出:
[INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-**1.7**
The default JRE for the workspace isn't Java 7 , it is Java 8 , like you can see looking at the following Eclipse config file: 工作区的默认JRE不是Java 7 ,而是Java 8 ,就像您看到以下Eclipse配置文件一样:
<workspace>\.metadata\.plugins\org.eclipse.core.runtime\.settings\org.eclipse.jdt.launching.prefs.
that contains the following data: 包含以下数据:
org.eclipse.jdt.launching.PREF_VM_XML=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?>
<vmSettings defaultVM\="57,org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType13,1538040823497*">
<vmType id\="org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType">
<vm id\="1431694854640" name\="jdk1.7.0_40" path\="C\:\\Program Files\\Java\\jdk1.7.0_40"/>
<vm id\="1447417000092" name\="jdk1.6.0_45" path\="C\:\\Program Files\\Java\\jdk1.6.0_45"/>
<vm id\="1538040823497" name\="jdk1.8.0_65" path\="C\:\\Program Files\\Java\\jdk1.8.0_65"/>
</vmType>
</vmSettings>
As you may notice by looking at the above configuration, the default VM has the vm id "1538040823497", which is named jdk1.8.0_65 , and resides in C\\:\\\\Program Files\\\\Java\\\\jdk1.8.0_65
. 通过查看上述配置,您可能会注意到,默认VM具有vm id“ 1538040823497”,名为jdk1.8.0_65 ,位于
C\\:\\\\Program Files\\\\Java\\\\jdk1.8.0_65
。
This VM is correctly registered as Workspace Default in Eclipse Preferences, Java/Installed JREs, is marked as a "perfect match" within the Execution Environment JAVASE-1.8. 该VM已在Eclipse首选项Java /已安装的JRE中正确注册为Workspace Default,在执行环境JAVASE-1.8中被标记为“完全匹配”。
I cannot see anything why Maven Eclipse Plugin considers org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7
as the correct choice, and not JAVASE-1.8 . 我什么都看不到,为什么Maven Eclipse插件将
org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7
视为正确的选择,而不是JAVASE-1.8 。
I already deleted all JREs and registered them newly. 我已经删除了所有JRE并重新注册了它们。
Now there's exactly one 1.6, 1.7 and 1.8 Environment, each with a "perfect match", and 1.8 is checked as default (as you can see above). 现在只有一个1.6、1.7和1.8环境,每个环境都有一个“完全匹配”,并且默认情况下检查1.8(如上所示)。
I have to manually correct the project each time I generated it (Edit Build Path, change JRE library from 7 to 8), since all files using Java 8 features like streams or lambda functions signal compiler errors unless I assign the correct JRE manually. 我必须在每次生成项目时手动对其进行纠正(编辑构建路径,将JRE库从7更改为8),因为除非我手动分配了正确的JRE,否则所有使用Java 8功能(例如流或lambda函数)的文件都将指示编译器错误。
I already tried and manipulate org.eclipse.jdt.launching.prefs
, redefine all JREs, pray, curse or ask an Ouija board, to no avail, always Java 7 is assigned by the eclipse plugin (version 2.10, by the way). 我已经尝试并操作了
org.eclipse.jdt.launching.prefs
,重新定义了所有JRE,祈祷,诅咒或询问Ouija板,但徒劳无功,总是Java 7是由eclipse插件分配的(顺便说是版本2.10)。
Any ideas, anyone? 有什么想法吗?
In your pom file, try to use this: 在您的pom文件中,尝试使用此命令:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
You may also reference this link: 您也可以引用此链接:
https://dzone.com/articles/maven-eclipse-and-java-9 https://dzone.com/articles/maven-eclipse-and-java-9
Or if all fails, try eclipse oxygen, a newer version (not the newest release but much better than Mars IMO) that has Maven Integration plugin pre-installed, all you need is to add a m2e-connector plugin. 或者,如果所有方法均失败,请尝试使用eclipse oxygen,它是一个预安装了Maven Integration插件的较新版本(不是最新版本,但比Mars IMO更好),您所需要做的就是添加一个m2e-connector插件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.