Eclipse 如何仅使用 JRE 编译类?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1642338/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 14:05:27  来源:igfitidea点击:

How does Eclipse compile classes with only a JRE?

eclipsecompilationjava

提问by glmxndr

I need to batch a compilation with a special JRE which has been "customized".

我需要使用已“定制”的特殊 JRE 对编译进行批处理。

Eclipse is able to compile the classes with this JRE, but I need to make a build script outside of Eclipse.

Eclipse 能够使用这个 JRE 编译类,但我需要在 Eclipse 之外制作一个构建脚本。

What is the method used by Eclipse to generate the .class files without a JDK?

Eclipse 在没有 JDK 的情况下使用什么方法生成 .class 文件?

回答by Aaron Digulla

Eclipse comes with its own compiler for the following reasons:

Eclipse 带有自己的编译器,原因如下:

  • Incremental compilation (can compile just the changed parts of the project which can mean more than the amount of files you just saved, for example, when you changed some global)
  • The Eclipse compiler can create a class file even when the code contains errors. This allows to run the project even though not everything compiles.
  • The compiler provides Eclipse with an ASTso it can do all kinds of fancy stuff (like the outline, show you all the places where the variable under the cursor is used, etc) at no extra cost (i.e. it doesn't have to run the compiler andanother parser).
  • 增量编译(可以只编译项目的更改部分,这可能意味着比您刚保存的文件数量更多,例如,当您更改某些全局时)
  • 即使代码包含错误,Eclipse 编译器也可以创建类文件。这允许运行项目,即使不是所有的东西都能编译。
  • 编译器为 Eclipse 提供了一个AST,因此它可以在不增加成本的情况下(即它不必运行编译器另一个解析器)。

回答by Yuval

I believe Eclipse comes with internal compilers, and you can choose the compatibility to Java 1.3 through 1.6 (check the Preferences menu, under Java->Compiler). So Eclipse doesn't need an external JDK to compile, because it comes with it is self-sufficient.

我相信 Eclipse 带有内部编译器,您可以选择与 Java 1.3 到 1.6 的兼容性(检查 Java->Compiler 下的 Preferences 菜单)。所以Eclipse 不需要外部JDK 来编译,因为它自带的它是自给自足的。

If you want to create a build script outside of Eclipse, you're gonna need an external compiler, like the one that comes with the real JDK.

如果您想在 Eclipse 之外创建一个构建脚本,您将需要一个外部编译器,就像真正的 JDK 附带的那个一样。

回答by BalusC

For the case one is interested: Eclipse's compiler is part of JDT core.

对于感兴趣的案例:Eclipse 的编译器是JDT 核心的一部分。

回答by Jesper

Eclipse was originally created by IBM. Eclipse has its own built-in Java compiler which is based on IBM's Java compiler, Jikes.

Eclipse 最初是由 IBM 创建的。Eclipse 有自己的内置 Java 编译器,它基于 IBM 的 Java 编译器Jikes