views:

38

answers:

3

I have looked for an answer for this nearly every where that I can think of, but there doesn't seem to be any way to actually SEE what Eclipse "runs" to compile the projects (as it does need the JDK installed and visible to actually build). I ask because I imported a few jars into my project, and even though I've looked through all the javac documentation, I can't seem to figure out how to mimic it quite like Eclipse does. I really, really need to be able to compile on the command line in this case - Eclipse or any other IDE just isn't what is needed.

I started to look through the Eclipse source, and although this sounds lazy, I just became overwhelmed and figured I would ask here first, hoping someone else had the same question at one point.

A: 

Eclipse JDT does not require the JDK and does not use javac - it uses it's own compiler.

You can see the classpath by reading your project .classpath file. The various builders that are used to perform build operations (Java, or whatever the project builds) are listed in the .project file. (These are also listed in the project settings.)

It is possible to invoke Eclipse to build your project in headless mode, or write Ant scripts that can be executed both with the JDK and within Eclipse, or install Maven support for internal and external building. It is also possible to configure the project builders to rely only on external tools.

McDowell
Thanks for that - I knew about the class path and project files, but ended up figuring out how to solve my compile problem. Learned something new today though - didn't know eclipse had it's own built in compiler.
alleywayjack
Is Eclipse's compiler just a wrapper around the same compiler core that the javac program is wrapped around, or is it a separate compiler altogether? If the latter, why would they reinvent the (possibly inferior) wheel?
Bart van Heukelom
@Bart - it's separate. There are a number of reasons you might do this (not all of which are technical); I imagine it offers better integration with the IDE - the `javac` API has traditionally been private (no standard API). I expect many of the issues are to do with licensing and control of the software stack (important to big players where the cost of writing a compiler is insignificant compared to the risks).
McDowell
Yeah, I' ve decided to make that comment a question: http://stackoverflow.com/questions/3061654/what-is-the-difference-between-javac-and-the-eclipse-compiler/
Bart van Heukelom
A: 

Look at these two articles.
http://www.eclipse.org/articles/Article-Builders/builders.html
http://www.eclipsepluginsite.com/builders-natures-markers.html

Look at your .classpath file and start building an ANT build.xml. You need to do this to be able to have consistent builds on a build machine anyways. It is unlikely that a build server would have eclipse installed on it anyways.

Maven is also another tool that is used for builds. In our shop we use Ant.

Romain Hippeau
A: 

Have a look at ant4eclipse - this project allows for generating the appropriate ant data structures for invoking <javac> from the .classpath files and a projectSet.psf file.

By using this we can use Eclipse "natively" and bend ant to conform to Eclipse. The usual approach is the other way around.

Thorbjørn Ravn Andersen
You can use the javac attribute compiler="org.eclipse.jdt.core.JDTCompilerAdapter" to use the eclipse compiler when running javac from ant. This is what PDE does when performing headless releng builds.
Andrew Niefer