views:

601

answers:

4

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 ?

+4  A: 

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
+9  A: 

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
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
Accepted thanks to the comment from Joachim. I found the same link which gives full description on how to use the BatchCompiler class.
subtenante
A: 

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

Jesper
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
Ok, if that's so then the Eclipse compiler isn't exactly Jikes. At least they both originated from IBM.
Jesper
A: 

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

BalusC