简体   繁体   English

在Eclipse中为不同的项目使用jdk 1.6和jdk 1.7

[英]Using both jdk 1.6 and jdk 1.7 for different projects in Eclipse

I am using Eclipse with JDK 1.7. 我正在使用Eclipse和JDK 1.7。 My previous projects are developed in java 7 and JDK 1.7. 我以前的项目是用java 7和JDK 1.7开发的。 Now, I want to build a new project under JDK 1.6 in Eclipse. 现在,我想在Eclipse中的JDK 1.6下构建一个新项目。 Is it possible to do that so that some projects are based on JDK 1.7 and some others are based on JDK 1.6 without conflicts? 有可能这样做,以便一些项目基于JDK 1.7而其他一些项目基于JDK 1.6而没有冲突吗?

If this can be done, please let me know how to do it step by step. 如果可以这样做,请告诉我如何逐步完成。

Update: My default JDK is 1.7. 更新:我的默认JDK是1.7。 I created a new project that is based on jdk1.7 by default. 我创建了一个默认基于jdk1.7的新项目。 And then I go to the property of this project, and then java compiler, then change the compliance settings as the image shows below. 然后我转到这个项目的属性,然后是java编译器,然后更改合规性设置,如下图所示。 But there is some error occurred. 但是发生了一些错误。 What could be the reason causes this error? 可能是什么原因导致此错误?

在此输入图像描述

在此输入图像描述

The following is the "problem" view 以下是“问题”视图

在此输入图像描述

After some research, I have solved this problem. 经过一番研究,我解决了这个问题。 please see the reference about how to fix the facet version. 请参阅有关如何修复构面版本的参考

You can set overall workspace properties to use one version of Java and set individual project properties to use another. 您可以将整体工作空间属性设置为使用一个版本的Java,并将各个项目属性设置为使用另一个。

  • To set overall workspace properties, click on Window > Preferences , then navigate to Java > Compiler . 要设置整体工作区属性,请单击Window > Preferences ,然后导航到Java > Compiler
  • To set project properties, right-click on the project and select Properties . 要设置项目属性,请右键单击项目,然后选择“ 属性” Navigate to Java Compiler and check "Enable project specific settings" 导航到Java Compiler并选中“启用项目特定设置”

You can choose from among the installed JREs for either setting. 您可以从已安装的JRE中进行选择以进行任一设置。 To tell Eclipse about a newly installed JRE, you can open the workspace preferences and navigate to Java > Installed JREs and then click the "Add" button. 要告知Eclipse有关新安装的JRE的信息,可以打开工作区首选项并导航到Java > Installed JREs ,然后单击“添加”按钮。

This can be done for an Eclipse Run Configuration. 这可以在Eclipse Run Configuration中完成。 You may define multiple such configurations, each of which will reference a "main class" in one of your projects. 您可以定义多个这样的配置,每个配置将引用您的一个项目中的“主类”。

  1. In Window -> Preferences -> Java -> Installed JREs define a location for each JRE/JDK. Window - > Preferences - > Java - > Installed JREs中定义每个JRE / JDK的位置。

  2. For a given Eclipse project: 对于给定的Eclipse项目:

    • right click on the project, select Properties -> Java Compiler , override and set compiliance level settings. 右键单击项目,选择Properties - > Java Compiler ,覆盖并设置compiliance level设置。

    • Check Use compliance from ... , visit the Java Build Path and be sure you have a JRE Library set that matches the desired compliance level. 选中使用合规性... ,访问Java构建路径并确保您具有与所需合规级别匹配的JRE库集。

  3. For a given Eclipse Run Configuration: Run -> Run Configurations... -> Java Application , select an old or create a new configuration, select the JRE tab and specify the Runtime JRE . 对于给定的Eclipse运行配置: 运行 - >运行配置... - > Java应用程序 ,选择旧的或创建新配置,选择JRE选项卡并指定运行时JRE

You can change the JDK used by project under Project properties( alt+enter )-> Installed JREs. 您可以在项目属性( alt+enter ) - >已安装的JRE下更改项目使用的JDK。 Also Debug Configuration is your friend. 调试配置也是你的朋友。 You can set what JDK to use when launching/running an app/program in Eclipse. 您可以设置在Eclipse中启动/运行应用程序/程序时要使用的JDK。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM