34

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

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

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

BuZZ-dEE
  • 6,075
  • 12
  • 66
  • 96
glmxndr
  • 45,516
  • 29
  • 93
  • 118

4 Answers4

48

Eclipse comes with its own compiler for the following reasons:

  • 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 AST so 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 and another parser).
Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • 12
    There's even documentation on how to run the Eclipse compiler as a standalone application outside of Eclipse: http://help.eclipse.org/galileo/topic/org.eclipse.jdt.doc.isv/guide/jdt_api_compile.htm – Joachim Sauer Oct 29 '09 at 09:06
  • Accepted thanks to the comment from Joachim. I found the same link which gives full description on how to use the BatchCompiler class. – glmxndr Oct 29 '09 at 09:34
  • Thanks for good explanation. Where did you find that information? It's very hard to me to find information about features of Eclipse's compiler. – Sanghyun Lee Aug 11 '12 at 07:32
  • All over the net. I'm reading [Planet Eclipse](http://www.planeteclipse.org/), the [Eclipse Forums](http://www.eclipse.org/forums) and the source code. – Aaron Digulla Aug 13 '12 at 07:36
  • 1
    @AaronDigulla So, why does it force to select **"installed JREs"** in preferences? – Can Mingir Apr 25 '14 at 16:52
  • A JDK (Java SE Development Kit) always includes a JRE (Java Runtime Environment), so you can point Eclipse to both. For Eclipse's JDT (Java Developer Tools) itself, it doesn't matter. Some tools like m2e need a full JDK, though. Only such plugins force you to use a JDK. If you don't use them, you're not forced by anyone to anything :-) – Aaron Digulla Apr 27 '14 at 12:42
  • @AaronDigulla, So are you saying that Eclipse has it's on JRE as well? Or are you saying that Eclipse only do the compiling but we still need to install a JRE on our system to test-run code? – Pacerier Aug 24 '14 at 21:36
  • @Pacerier: To run Java code (no matter how), you at least need a JRE. So to run Eclipse itself or code you write inside of Eclipse, you need at least a JRE (a JDK will work just as well). If you use the m2e plugin, you need a JDK to start Eclipse. To compile code outside Eclipse, you need a JDK. To compile code inside of Eclipse, you don't need a JDK. If you use the m2e plugin, you need a JDK to run Eclipse and for tasks like "mvn install" since the Maven compiler plugin needs a Java compiler and the default is the one from the JDK. – Aaron Digulla Aug 26 '14 at 11:44
  • @AaronDigulla, No I meant does Eclipse come with its own JRE too? E.g. I have JRE version 6 which I use to run Eclipse, then can I use Eclipse's embedded JRE to run code targeted for JRE version 7? – Pacerier Aug 26 '14 at 13:17
  • @Pacerier: Eclipse doesn't come with a JRE. – Aaron Digulla Aug 26 '14 at 14:11
  • @AaronDigulla, Thanks for sharing your knowledge. Its a good read. – Jagadish Talluri Nov 19 '15 at 12:36
5

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.

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.

Yuval
  • 7,987
  • 12
  • 40
  • 54
2

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

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

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

Jesper
  • 202,709
  • 46
  • 318
  • 350
  • I don't think the Eclipse compiler is based on Jikes. It may very well be inspired by it, but since jikes is implemented in C++ and the Eclipse compiler is pure Java, I doubt that they inherited any major code parts. – Joachim Sauer Oct 29 '09 at 09:56
  • Ok, if that's so then the Eclipse compiler isn't exactly Jikes. At least they both originated from IBM. – Jesper Oct 29 '09 at 12:57