我如何让 Eclipse 为 Java 使用不同的编译器版本? [英] how do I get eclipse to use a different compiler version for Java?

查看:23
本文介绍了我如何让 Eclipse 为 Java 使用不同的编译器版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看起来这应该是一个简单的任务,在首选项菜单中为不同的 JRE 提供了选项,并且能够为每个项目设置不同的编译器和构建路径.然而,它似乎也根本不起作用.

It seems like this should be a simple task, with the options in the Preferences menu for different JREs and the ability to set different compiler and build paths per project. However, it also seems to simply not work.

例如,我将我的 JAVA_HOME 设置为 Java 1.6 的 jre.我仍然不清楚 Eclipse 是如何使用它的,但它似乎默认为这个并且不采用项目覆盖.我还安装了 Java 1.5,并在 Eclipse 的 Java->Installed JREs 部分为此添加了 JRE.

For example, I have my JAVA_HOME set to a jre for Java 1.6. It's still not clear to me how Eclipse uses this, but it appears to be defaulting to this and not taking the project overrides. I have also installed Java 1.5, and added a JRE for this in eclipse in the Java->Installed JREs section.

在我的项目中,我将编译器合规性级别设置为 1.5.在项目的构建路径中,我添加了 Java 1.5 JRE 的系统库.但是,我收到了一个实现 PreparedStatement 的类的编译错误,因为它没有实现只存在于 Java 1.6 PreparedStatement 中的抽象方法.具体来说,方法

In my project, I've set the compiler compliance level to 1.5. In the build path for the project, I've added the System Library for the Java 1.5 JRE. However, I'm getting compile errors for a class that implements PreparedStatement for not implementing abstract methods that only exist in Java 1.6 PreparedStatement. Specifically, the methods

setAsciiStream(int, InputStream, long) and 
setAsciiStream(int, InputStream)

奇怪的是,当我们针对 Java 1.4 编译它时它起作用了,它最初是为 Java 1.4 编写的.我们为 Java 1.4 添加了 JRE 并在项目中引用了该系统库,并将项目的编译器级别设置为 1.4,它工作正常.但是当我做同样的更改以尝试指向 Java 1.5 时,它改为使用 1.6.

Strangely enough, it worked when we were compiling it against Java 1.4, which it was originally written for. We added the JREs for Java 1.4 and referenced that system library in the project, and set the project's compiler level to 1.4, and it works fine. But when I do the same changes to try to point to Java 1.5, it instead uses 1.6.

知道为什么吗?

推荐答案

从菜单栏:项目 -> 属性 -> Java 编译器

From the menu bar: Project -> Properties -> Java Compiler

启用项目特定设置(选中)取消选中从执行环境使用合规性"....选择所需的编译器合规级别"

Enable project specific settings (checked) Uncheck "use Compliance from execution environment '.... Select the desired "compiler compliance level"

这将允许您使用1.6"JDK 编译1.5"代码.

That will allow you to compile "1.5" code using a "1.6" JDK.

如果你想真正使用 1.5 JDK 来生成1.5"兼容代码,那么安装一个合适的 1.5 JDK 并通过以下方式告诉 eclipse 它的安装位置:

If you want to acutally use a 1.5 JDK to produce "1.5" compliant code, then install a suitable 1.5 JDK and tell eclipse where it is installed via:

窗口 -> 首选项 -> 已安装的 JRE

Window -> preferences -> Installed JREs

然后回到你的项目

项目 -> 属性 -> Java 构建路径 -> 库

Project -> properties -> Java Build Path -> libraries

删除 1.6 系统库,并且:添加库... -> JRE 系统库 -> 备用 JRE -> 你想要的 JRE.

remove the 1.6 system libaries, and: add library... -> JRE System LIbrary -> Alternate JRE -> The JRE you want.

验证正确的 JRE 在项目的构建路径上,保存所有内容,然后享受!

Verify that the correct JRE is on the project's build path, save everything, and enjoy!

这篇关于我如何让 Eclipse 为 Java 使用不同的编译器版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆