如何为 Eclipse IDE 设置 Eclipse 以外的 Java 编译器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4163312/
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
How to set up other-than-eclipse Java compiler for Eclipse IDE
提问by Ralkie
I noticed that Eclipse IDE (for Java, version 3.5.1) uses it's own java compiler(s), but I can't find how to change it. Is it even possible?
我注意到 Eclipse IDE(对于 Java,版本 3.5.1)使用它自己的 Java 编译器,但我找不到如何更改它。甚至有可能吗?
Maybe it's kinda trivial, but after many years of using IntelliJ IDEA I find returning to Eclipse a little bit awkward.
也许这有点微不足道,但在使用 IntelliJ IDEA 多年后,我发现回到 Eclipse 有点尴尬。
Thanks.
谢谢。
UPDATE: Since more detailed explanation was requested, I'm doing that.
更新:由于要求更详细的解释,我正在这样做。
So, recently I was helping out some fellow Java developer and noticed he is using Eclipse w/o Sun's JDK. Since company-wide we are using only Sun's JDKs, I found it rather strange.
所以,最近我正在帮助一些 Java 开发人员,并注意到他正在使用 Eclipse w/o Sun 的 JDK。由于在全公司范围内我们只使用 Sun 的 JDK,我觉得这很奇怪。
It appeared that he has only Eclipse and no additional tools for compiling java code (like javac) are required. This is because Eclipse comes bundled with its own compiler (check thisfor more details).
看起来他只有 Eclipse,不需要额外的编译 java 代码的工具(比如 javac)。这是因为 Eclipse 捆绑了它自己的编译器(有关更多详细信息,请查看这里)。
By itself I find this feature quite nice, and I believe there were good reasons for that. But I would like all our company developers to use same compiler to generate java bytecode (.class files). And to run this in same JVMs. Just for sake of having as unified environment as possible and eliminating additional environment-specific issues. I have no problem with specifying JRE in Eclipse.
就其本身而言,我觉得这个功能非常好,我相信这是有充分理由的。但我希望我们公司的所有开发人员都使用相同的编译器来生成 java 字节码(.class 文件)。并在相同的 JVM 中运行它。只是为了拥有尽可能统一的环境并消除其他特定于环境的问题。我在 Eclipse 中指定 JRE 没有问题。
But I failed to find how to change default Java compiler to javac. On the other hand, my primary IDE IntelliJ IDEA allows do that (choose between javac, jikes or eclipse compilers). So I just wanted to know if same is possible in Eclipse or not.
但是我没有找到如何将默认 Java 编译器更改为 javac。另一方面,我的主要 IDE IntelliJ IDEA 允许这样做(在 javac、jikes 或 eclipse 编译器之间进行选择)。所以我只是想知道在 Eclipse 中是否可以这样做。
Additionally:
此外:
- No, I have no real problems with Eclipse compiler as such, this is simply matter of being able to choose.
- I know that Apache Ant and other solutions can be used to compile Java code with any compiler. But here I'm interested in Eclipse and its integrated project building (e.g. menu items under Projectmenu).
- 不,我对 Eclipse 编译器没有真正的问题,这只是能够选择的问题。
- 我知道 Apache Ant 和其他解决方案可用于使用任何编译器编译 Java 代码。但在这里,我对 Eclipse 及其集成项目构建感兴趣(例如,项目菜单下的菜单项)。
采纳答案by nanda
What do you want to have? If you want to have the classes created by Sun compiler, you can build them using Ant. Eclipse uses its own compiler because Sun's compiler is not designed to be used in auto-compiled environment.
你想拥有什么?如果要让 Sun 编译器创建类,可以使用 Ant 构建它们。Eclipse 使用自己的编译器,因为 Sun 的编译器不是为在自动编译环境中使用而设计的。
From the JDT website:
从JDT 网站:
An incremental Java compiler. Implemented as an Eclipse builder, it is based on technology evolved from VisualAge for Java compiler. In particular, it allows to run and debug code which still contains unresolved errors.
增量 Java 编译器。作为 Eclipse 构建器实现,它基于从 VisualAge for Java 编译器演变而来的技术。特别是,它允许运行和调试仍然包含未解决错误的代码。
Keep in mind that for the library itself, Eclipse will still use the one from Sun's compiler that can be set using the procedure explained by another answers (NimChimpsky and The Elite).
请记住,对于库本身,Eclipse 仍将使用来自 Sun 编译器的库,该编译器可以使用另一个答案(NimChimpsky 和 The Elite)解释的过程进行设置。
回答by simpatico
While I've also looked for this, the only solution I found was to use Maven. With maven-compiler-plugin you can specify the compiler to use, and eclipse will delegate to it. I hope a similar trick can be done for Ant-based projects.
虽然我也在寻找这个,但我找到的唯一解决方案是使用 Maven。使用 maven-compiler-plugin 您可以指定要使用的编译器,eclipse 将委托给它。我希望对基于 Ant 的项目可以做一个类似的技巧。
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<compilerId>javac</compilerId>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-javac</artifactId>
<version>1.6</version>
</dependency>
</dependencies>
</plugin>
dp4jmaventestis a working demo using this config.
dp4jmaventest是使用此配置的工作演示。
Bug 341842is an Eclipse feature request for such support.
错误 341842是对此类支持的 Eclipse 功能请求。
回答by Buhake Sindi
This is how to add your own JDK/JRE:
这是添加您自己的 JDK/JRE 的方法:
- Goto
Windows
->Preferences
menu. - On Preferences window, in the left drop-down, select,
Java
->Installed JREs
. - Click on the
Add
bitton (on the right), selectStandard VM
, then a dialog box will appear with titleAdd JRE
. - On
JRE home
: field, click ondirectory
button and browse to you JRE/JDK root folder. Once selected, it will auto-complete and click finish.
- 转到
Windows
->Preferences
菜单。 - 在首选项窗口的左侧下拉列表中,选择
Java
->Installed JREs
。 - 单击
Add
位元(右侧),选择Standard VM
,然后会出现一个标题为 的对话框Add JRE
。 - 在
JRE home
: 字段上,单击directory
按钮并浏览到您的 JRE/JDK 根文件夹。选择后,它将自动完成并单击完成。
Once you're done, go back to the Preferences
window, and tick the radio button of your added JRE/JDK to make it default.
完成后,返回Preferences
窗口,勾选添加的 JRE/JDK 的单选按钮以使其成为默认值。
Hope this helps.
希望这可以帮助。
回答by NimChimpsky
right click project > properties > java compiler
右键单击项目> 属性> Java 编译器