views:

20

answers:

2

I'd like to do some command-line Java compiling of individual Java source files on a machine that has Eclipse installed. However, I don't have permissions to install a full Java SDK on this machine.

I understand that Eclipse compiles through its JDT, not using javac.

Is is possible to use the Eclipse compiler from the command line?

+1  A: 

I haven't tried it myself, but there are some instructions about running the "batch compiler". They may be helpful to you.

Jon Skeet
+1  A: 

A few more minutes of searching and I found this in the Eclipse documentation, under the section "Running the Batch Compiler":

java -jar org.eclipse.jdt.core_3.4.0<qualifier>.jar -classpath rt.jar A.java

or:

java -jar ecj.jar -classpath rt.jar A.java

I also found this Q/A on how to build an entire Eclipse project from the command line, which contains some of the same information, but since it didn't show up in my initial search I'm leaving this question open.

(And about 2 sec before I was going to click "Post Your Answer", Jon Skeet's reply popped up.)


The exact syntax that worked for me (Sun JRE is in the Windows PATH, Eclipse version is Galileo build 20100218-1602):

java -jar "C:\Program Files\eclipse\plugins\org.eclipse.jdt.core_3.5.2.v_981_R35x.jar" test.java

I omitted the -classpath rt.jar and it still worked. Couldn't find the 'ecj.jar' file in this build.

It seems that the specific instructions for this do change from release to release, so caveat coder.

system PAUSE

related questions