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?
javac compiler. However, both Eclipse Java compiler and javac implement the Java Language Specification (JLS), the bytecode they produce is almost the same. Except for some corner cases they may produce different bytecode or code compiles with Eclipse but not compiles with javac.
org.eclipse.jdt.core. The Java model is the set of classes that model the objects associated with creating, editing, and building a Java program. org.eclipse.jdt.core.compiler. This package contains compiler associated infrastructure APIs.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With