简体   繁体   English

如何为Eclipse项目更改JDK版本

[英]How to change JDK version for an Eclipse project

I need to write a project that's only compatible with Java 1.5. 我需要编写一个仅与Java 1.5兼容的项目。 I have Java 1.6 installed. 我已经安装了Java 1.6。 Is there some form of backwards compatibility to get Eclipse to compile with 1.5? 是否存在某种形式的向后兼容性,以使Eclipse用1.5进行编译?

Do I have to install Java 1.5 to get it to show here? 我必须安装Java 1.5才能在此处显示它吗? Or maybe there is another way? 也许还有另一种方法?

在此处输入图片说明 .

Click on the Add Library button. 单击添加库按钮。 It brings your screen to point to the Java location. 它使您的屏幕指向Java位置。

Select " Directory ", button right besides JRE home and point to the installed folder location. 选择“ 目录 ”,在JRE主页旁边的按钮,然后指向已安装的文件夹位置。

Even though you want to just 1.5 compiler project, you can achieve it by changing compiler settings in Eclipse instead of removing 1.6 JRE and add 1.5 JRE. 即使只需要1.5个编译器项目,也可以通过在Eclipse中更改编译器设置来实现,而不必删除1.6 JRE并添加1.5 JRE。

GOTO -->JAVA--Compiler---> and change compiler level to `1.5` instead of `1.6`

As davidfmatheson suggested, 正如davidfmatheson所建议的那样,

Just be careful, especially if you're setting this up for a team of people to work on. 请小心,特别是如果您要为此设置一组人员进行工作。 If anyone uses anything that is new or changed in 1.6, it will compile, but not run in an environment with JRE 1.5. 如果有人使用1.6中的新内容或更改的内容,它将进行编译,但不能在具有JRE 1.5的环境中运行。

Click on the Window tab in Eclipse, go to Preferences and when that window comes up, go to JavaInstalled JREsExecution Environment and choose JavaSE-1.5. 单击Eclipse中的“ 窗口”选项卡,转到“首选项”,然后在出现该窗口时,转到“ Java” →“ 已安装的JRE” →“ 执行环境”,然后选择JavaSE-1.5。 You then have to go to Compiler and set the Compiler compliance level . 然后,您必须转到Compiler并设置Compiler合规级别

改变JRE

在此处输入图片说明

Right click project -> Properties -> Java Build Path -> select JRE System Library click Edit and select JDK or JRE after then click Java Compiler and select Compiler compliance level to 1.8 右键单击项目->属性-> Java构建路径 ->选择JRE系统库,单击编辑,然后选择JDKJRE ,然后单击Java编译器,然后选择编译器遵从性级别1.8

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

See the page Set Up JDK in Eclipse . 请参阅在Eclipse中设置JDK页面。 From the add button you can add a different version of the JDK... 从添加按钮,您可以添加其他版本的JDK ...

The JDK (JAVA_HOME) used to launch Eclipse is not necessarily the one used to compiled your project. 用于启动Eclipse的JDK(JAVA_HOME)不一定是用于编译项目的JDK。

To see what JRE you can select for your project, check the preferences: 要了解JRE,你可以为你的项目选择,检查首选项:

GeneralJava Installed JRE 常规Java已安装JRE

By default, if you have not added any JRE, the only one declared will be the one used to launched Eclipse (which can be defined in your eclipse.ini ). 默认情况下,如果您未添加任何JRE,则声明的唯一一个将是用于启动Eclipse的声明(可以在eclipse.ini中定义)。

You can add any other JRE you want, including one compatible with your project. 您可以添加任何其他所需的JRE,包括与项目兼容的JRE。

After that, you will need to check in your project properties (or in the general preferences) what JRE is used, with what compliance level: 之后,您将需要检入您的项目属性(或在常规首选项中),使用什么JRE,以及什么合规级别:

替代文字
(source: standartux.fr ) (来源: standartux.fr

Eclipse - specific Project change JDK Version - Eclipse-特定的项目更改JDK版本-

If you want to change any jdk version of A specific project than you have to click ---> Project --> JRE System Library --> Properties ---> Inside Classpath Container (JRE System Library) change the Execution Environment to which ever version you want eg 1.7 or 1.8. 如果要更改某个特定项目的任何jdk版本,则必须单击--->项目-> JRE系统库->属性--->内部类路径容器(JRE系统库),然后将执行环境更改为您想要的任何版本,例如1.7或1.8。

If you are using maven build tool then add the below properties to it and doing a maven update will solve the problem 如果您正在使用maven构建工具,则向其添加以下属性,并执行maven更新将解决该问题

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

In the preferences section under Java -> Installed JREs click the Add button and navigate to the 1.5 JDK home folder. 在Java->已安装JRE下的首选项部分中,单击添加按钮并导航到1.5 JDK主文件夹。 Then check that one in the list and it will become the default for all projects: 然后检查列表中的一个,它将成为所有项目的默认设置:

在此处输入图片说明

正如我在几分钟前面对此问题时,如果您尝试在使用较新JDK的环境中打开现有项目,请确保在项目属性->项目方面-> Java中输入JDK版本。

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

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