Eclipse + Maven:强制执行环境“JavaSE-1.6”而不是固定的 JDK
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4759242/
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
Eclipse + Maven: force Execution Environment "JavaSE-1.6" instead of fixed JDK
提问by sjngm
I'm using Eclipse as IDE and Maven outside of it to keep all dependencies up to date and update the Eclipse-project as such. In Eclipse I usually specify the JRE system library as an execution environment for any Java-project, usually "JavaSE-1.6".
我使用 Eclipse 作为 IDE,在它之外使用 Maven 以保持所有依赖项最新并更新 Eclipse 项目。在 Eclipse 中,我通常指定 JRE 系统库作为任何 Java 项目的执行环境,通常是“JavaSE-1.6”。
In the pom.xml I use the following lines:
在 pom.xml 中,我使用以下几行:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<projectNameTemplate>[groupId].[artifactId]</projectNameTemplate>
<downloadJavadocs>true</downloadJavadocs>
<wtpversion>2.0</wtpversion>
</configuration>
</plugin>
This seems to let Maven pick a JDK matching 1.6. It assigns its system libraries to the classpath of the project. However, it uses jdk1.6.20 directly rather than JavaSE-1.6.
这似乎让 Maven 选择了匹配 1.6 的 JDK。它将其系统库分配给项目的类路径。但是,它直接使用 jdk1.6.20 而不是 JavaSE-1.6。
Is there a way to make Maven use JavaSE-1.6 instead?
有没有办法让 Maven 改用 JavaSE-1.6?
EDIT: Here's the batch file that I use to run Maven:
编辑:这是我用来运行 Maven 的批处理文件:
SET JAVA_HOME=C:\Programme\java\jdk1.6.0_20
SET MAVEN_HOME=C:\Programme\apache-maven-2.2.1
SET MAVEN_OPTS=-Xmx512m -XX:MaxPermSize=128m
SET PATH=%JAVA_HOME%\bin;%MAVEN_HOME%\bin;%PATH%
SET EXTRA_MVN_OPTS=-Dmaven.test.skip=true
CD /D "%~dp0"
cmd /c mvn %EXTRA_MVN_OPTS% eclipse:clean eclipse:eclipse
cmd /c mvn %EXTRA_MVN_OPTS% clean install
回答by Sean Patrick Floyd
You can do it by setting a classpath container.
您可以通过设置类路径容器来实现。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<classpathContainers>
<classpathContainer>
org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6
</classpathContainer>
</classpathContainers>
</configuration>
</plugin>
Reference:
参考:
回答by Dave G
Go into Window > Preferences > Java > Installed JREs > Execution Environments
进入 Window > Preferences > Java > Installed JREs > Execution Environments
Select JavaSE-1.6, click the checkbox on the right that should indicate "perfect match"
选择 JavaSE-1.6,单击右侧的复选框,应指示“完美匹配”
then use "update project configuration" from the maven menu.
然后使用 Maven 菜单中的“更新项目配置”。
回答by Raghuram
Since you are using maven
and eclipse
, perhaps you should use M2Eclipseplugin. The maven project (built by maven by setting JAVA_HOME=C:\Program Files\Java\jdk1.6.0_23
) imported in Eclipse, shows up with JRE System Library
as JavaSE-1.6
由于您正在使用maven
and eclipse
,也许您应该使用M2Eclipse插件。JAVA_HOME=C:\Program Files\Java\jdk1.6.0_23
在 Eclipse 中导入的 maven 项目(由 maven 通过 setting 构建)显示JRE System Library
为JavaSE-1.6