Eclipse JDK 设置如何影响系统的 JDK 设置 [英] How is the Eclipse JDK setting affecting the system's JDK setting

查看:19
本文介绍了Eclipse JDK 设置如何影响系统的 JDK 设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 Mac OSX 上编译引用第三方 JAR 的 Grails 应用程序.尽管我的系统的 JRE 和 JDK 设置为 Java 1.6,但我总是遇到 编译错误:java.lang.UnsupportedClassVersionError:.class 文件中的错误版本号访问 JAR 中的类时.此外,在测试现有的 Grails 应用程序时,应用程序的默认统计信息显示它正在运行 Java 1.6.所以我真的没有比尝试更改 Eclipse 中的 Java 设置更多的想法——我认为这很愚蠢,因为我没有使用 Eclipse 来开发这个应用程序——但是瞧——现在我的应用程序在命令上的编译线工作得很好!

I was trying to compile a Grails application referencing third party JARs on Mac OSX. Although my system's JRE and JDK is set to Java 1.6 I always got a Compilation error: java.lang.UnsupportedClassVersionError: Bad version number in .class file when accessing classes in the JAR. Also when testing an existing Grails app the default stats of the app where showing that it's running with Java 1.6. So I really didn't have more ideas than to try to change the Java settings in Eclipse - I thought that's stupid as I'm not using Eclipse for the devlopment of this application - but voila - now the compilation of my app on the command line works just fine!

谁能解释一下 Eclipse 在幕后做了什么?我之前手动设置了JAVA_HOME,没有效果.

Can anyone explain me what Eclipse is doing here behind the scenes? I've had set the JAVA_HOME manually before with no effect.

推荐答案

用于启动 eclipse 的 JDK (JAVA_HOME) 不一定是用于编译项目的 JDK.

The JDK (JAVA_HOME) used to launched eclipse is not necessarily the one used to compiled your project.

要查看您可以为您的项目选择哪些 JRE,请查看首选项

To see what JRE YOU y can select for your project, check the preferences

General > Java Installed JRE

默认情况下,如果您没有添加任何 JRE,那么唯一声明的将是用于启动 eclipse 的那个(可以在您的 eclipse.ini).
您可以添加您想要的任何其他 JRE,包括与您的项目兼容的 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).
You can add any other JRE you want, including one compatible with your project.

之后,您需要检查您的项目属性(或在一般首选项中)使用的 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:

这篇关于Eclipse JDK 设置如何影响系统的 JDK 设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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