Eclipse:Java 构建路径中的 JRE 系统库重置

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

Eclipse: JRE System Library in Java Build Path reset

javaeclipsemavenbuildpathjava-8

提问by Jens Piegsa

For developing a JavaFX application I'm using a 4.3.1 snapshot of eclipsetogether with JDK 8 build b116. In my workspace projects the JRE library inclusion in the build path get resetted back to Java 1.4 all the time:

为了开发 JavaFX 应用程序,我将 Eclipse4.3.1 快照与 JDK 8 build b116 一起使用。在我的工作区项目中,包含在构建路径中的 JRE 库一直被重置回 Java 1.4:

the problem

问题

Unfortunately, this can only be fixed temporary (until the next eclipse restart):

不幸的是,这只能临时修复(直到下一次 eclipse 重新启动):

the temporary solution

临时解决办法

In the build section of my pom files I have:

在我的 pom 文件的构建部分,我有:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <debug>true</debug>
        <debuglevel>source,lines</debuglevel>
    </configuration>
</plugin>

I'd appreciate a less volatile solution.

我很欣赏一个不太不稳定的解决方案。

[UPDATE]The issue seems to be fixed with the current versions of

[更新]该问题似乎已在当前版本中解决

  • Java 8 (1.8.0-ea-b121),
  • Maven (3.1.1/1.5.0.20131218-0705),
  • m2e (1.5.0.20131218-1208) together with the
  • JDT beta patch [Update site].
  • Java 8 (1.8.0-ea-b121),
  • Maven (3.1.1/1.5.0.20131218-0705),
  • m2e (1.5.0.20131218-1208) 连同
  • JDT 测试补丁 [更新站点]。

采纳答案by René Link

The maven eclipse plugin (m2e) selects a java execution environment depending on the <source>and <target>properties for the maven compiler plugin.

maven eclipse 插件(m2e) 根据maven 编译器插件的<source><target>属性选择java 执行环境。

The problem is that there is neither a 1.8 execution environment available in Kepler nor the m2e maven compiler connector can map it yet.

问题是 Kepler 中既没有 1.8 执行环境可用,也没有 m2e maven 编译器连接器可以映射它。

Thus I see two solutions until it is supported in Kepler and m2e:

因此,在 Kepler 和 m2e 支持之前,我看到了两种解决方案:

  1. Let maven change the environment to 1.4 and map your 1.8 JDK to the execution environment J2SE-1.4. Then your project will use the correct JDK. But then all projects that depend on 1.4 will use the 1.8 JDK of course.

  2. Use the pluginManagenentto turn off the maven-compiler-pluginlifecycle handling. This should prevent the m2e plugin from updating the execution environment and you can set it manually.

    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                     <lifecycleMappingMetadata>
                           <pluginExecutions>
                                 <pluginExecution>
                                     <pluginExecutionFilter>
                                           <groupId>org.apache.maven.plugins</groupId>
                                           <artifactId>maven-compiler-plugin</artifactId>
                                           <versionRange>[1.0.0,)</versionRange>
                                         <goals>
                                             <goal>compile</goal>
                                         </goals>
                                     </pluginExecutionFilter>
                                     <action>
                                          <ignore />
                                     </action>
                                 </pluginExecution>
                           </pluginExecutions>
                     </lifecycleMappingMetadata>
               </configuration>
           </plugin>
        </plugins>
    </pluginManagement>
    
  1. 让 maven 将环境更改为 1.4,并将您的 1.8 JDK 映射到执行环境 J2SE-1.4。然后您的项目将使用正确的 JDK。但是所有依赖 1.4 的项目当然会使用 1.8 JDK。

  2. 使用pluginManagenent关闭maven-compiler-plugin生命周期处理。这应该可以防止 m2e 插件更新执行环境,您可以手动设置它。

    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                     <lifecycleMappingMetadata>
                           <pluginExecutions>
                                 <pluginExecution>
                                     <pluginExecutionFilter>
                                           <groupId>org.apache.maven.plugins</groupId>
                                           <artifactId>maven-compiler-plugin</artifactId>
                                           <versionRange>[1.0.0,)</versionRange>
                                         <goals>
                                             <goal>compile</goal>
                                         </goals>
                                     </pluginExecutionFilter>
                                     <action>
                                          <ignore />
                                     </action>
                                 </pluginExecution>
                           </pluginExecutions>
                     </lifecycleMappingMetadata>
               </configuration>
           </plugin>
        </plugins>
    </pluginManagement>