You build Eclipse Java code from the command line by compiling it with a standalone compiler or a headless build tool rather than letting the IDE do the work. The most direct route is the Eclipse Compiler for Java (ECJ), which ships as a single jar and reproduces Eclipse's own compiler behavior; for plugin, RCP, or OSGi projects, or for builds that must match the IDE exactly, you use Eclipse's headless build support (PDE build or the newer Eclipse Tycho). This guide covers both paths, the prerequisites each needs, the exact steps, how to verify success, and where each approach breaks down.
First, pin down what "Eclipse Java code" actually means
That phrase hides a fork in the road. A plain Java project you happen to edit in Eclipse is just ordinary Java source. It compiles with javac or ECJ, and there's nothing Eclipse-specific about the output. A second case is code that depends on Eclipse libraries, such as SWT, JFace, or the Eclipse runtime. That code still compiles normally, but the classpath must include the correct Eclipse jars. A third case is a real Eclipse plugin or feature, where the project has a MANIFEST.MF, a plugin.xml, and dependencies resolved against a target platform. Those need PDE-aware tooling, because a plain classpath can't express OSGi bundle resolution.
The distinction matters because choosing the wrong route wastes hours. If your project has a MANIFEST.MF and build.properties, treat it as a plugin. If it has only a .project and .classpath and source folders, it's an ordinary Java project and ECJ or Ant will do. If it has a pom.xml with Tycho packaging types like eclipse-plugin, it wants Maven with Tycho and a target platform.
One more ambiguity worth settling up front: building in Eclipse's workspace (the IDE's own incremental compiler) is a different operation from building on a machine that never opens the IDE. Everything below assumes the latter, which is what CI servers and reproducible local builds need.
Prerequisites before you type a command
You need a JDK, not just a JRE, because compilation requires the compiler tooling and, for some steps, javac. Confirm with java -version and javac -version; both should report the same major version that your code targets. On Windows, check that JAVA_HOME points at the JDK and that %JAVA_HOME%\bin is on PATH. On macOS and Linux, put $JAVA_HOME/bin on your PATH in your shell profile.
You also need your source tree and a clear idea of its dependencies. For the ECJ route, collect the jars your code compiles against into one place. For the Ant and PDE routes, that's what Eclipse's plugins directory or a target definition supplies. And you need the build tool itself: the ECJ jar, Apache Ant, or Maven, depending on the path you take. Keep all three tool versions pinned in your repository or build script so a teammate's machine and your CI runner agree.
Route one: compile with ECJ from the command line
ECJ is the compiler Eclipse has used internally for years, distributed as a standalone jar (historically on Maven Central under org.eclipse.jdt:ecj). It behaves like javac for most purposes but matches Eclipse's diagnostics and its handling of certain language features.
Step-by-step
1: Download the ECJ jar and note the exact version, for example ecj-3.38.0.jar. Put it in a tools/ folder inside the project and commit it, or fetch it in CI. 2: Create an output directory: mkdir -p build/classes. 3: Assemble the compile classpath. Join dependency jars with : on macOS and Linux, ; on Windows. 4: Compile with an explicit source level so the compiler doesn't guess:
java -jar tools/ecj-3.38.0.jar -source 17 -target 17 -encoding UTF-8 -d build/classes -cp "libs/" $(find src -name ".java")
On Windows PowerShell, replace the find substitution with an argument file (see below). 5: Expect silence on success. ECJ prints errors and warnings only, so an empty console and a populated build/classes is the signal that it worked.
For anything beyond a toy project, don't pass thousands of files on the command line. ECJ accepts an argument file with @:
java -jar tools/ecj.jar @compile.args
where compile.args holds one option or file per line. This sidesteps shell length limits on Windows, which are easy to hit. Alternatively, use ECJ's -classpath with a source directory listed directly, which makes it compile every .java file it finds there.
Two flags save real debugging time. -nowarn quiets warnings you don't care about in CI logs, though I'd leave warnings visible during local work. -proceedOnError keeps compiling past errors, which is useful for getting a full error report in one pass rather than fixing one problem per run. It should not be part of a release build.
Checking success
Look at three things: the exit code (zero on success), whether build/classes contains .class files for each expected source file, and whether any warnings you've classified as errors appeared. If ECJ reports "cannot find symbol," your classpath is missing a jar. If it reports "class file has wrong version," your -source/-target don't match the JDK you're running, or a dependency was compiled for a newer JVM than your target. Fix by aligning the target level and checking dependency bytecode versions with javap -verbose on a suspect class.
Limits of this route
ECJ compiles Java. It does not run annotations processors unless you ask it to, it does not resolve OSGi bundles, and it will not read your MANIFEST.MF to work out imports. Annotation processing needs explicit configuration (ECJ supports it, but you must supply the processor path), and generated sources need to be added to the source list yourself. If your project is a plugin, this route stalls at dependency resolution.
Route two: a reproducible Ant build
Ant remains the classic headless build tool in the Eclipse ecosystem, and a build file makes the steps above repeatable.
1: Install Ant (for example via your package manager or the official binary distribution) and verify ant -version. 2: Create build.xml at the project root with a compile target that sets srcdir, destdir, and a classpath reference, and uses with source, target, and encoding attributes. 3: To use ECJ rather than the JDK's compiler, add the ECJ jar and ant-jdt to the Ant classpath (Ant ships an ant-jdt.jar) and set the task's compiler="org.eclipse.jdt.core.JDTCompilerAdapter" attribute. Ant then calls ECJ through its adapter. 4: Run ant compile. Expect the same silence-on-success behavior. 5: Add a clean target that deletes the output directory, and run ant clean compile to confirm the build doesn't depend on leftovers.
The advantage over raw ECJ invocations is encapsulation: the classpath, encoding, and source level live in one file that runs identically on every machine and in CI. The cost is one more tool to install and one more file to maintain, and Ant build files grow brittle if you over-engineer them.
Route three: plugin and RCP projects with Tycho
If the project is an Eclipse plugin, RCP application, or feature, the correct answer is Eclipse Tycho, a Maven plugin set that resolves OSGi bundles against a target platform and builds them exactly as PDE would.
1: Install Maven and a JDK, then confirm mvn -version reports the JDK, not a JRE. 2: Ensure the project's parent pom.xml uses a Tycho packaging type such as eclipse-plugin, eclipse-feature, or eclipse-repository, and that the target platform is declared, either a .target file or a repository URL list. 3: Run mvn clean verify. Tycho fetches the target platform, compiles, and for repository packaging produces the p2 update site in target/repository. 4: Expect a long first run while the target platform downloads. Subsequent runs reuse the local Maven repository.
Success looks like a target/ directory with compiled classes and, for a repository build, a generated content.jar and artifacts.jar. The usual failure is a target platform mismatch: a bundle version that isn't in the declared repositories. The error names the missing bundle, and the fix is to add the repository that supplies it rather than fiddling with the classpath. I recommend Tycho over hand-rolled Jar assembly for anything with a MANIFEST.MF, because it verifies that your Require-Bundle and Import-Package declarations are actually satisfiable, which a plain classpath never does.
There's also the legacy PDE headless build driven by org.eclipse.ant.core.antRunner and a generated build.xml. It still works for older setups, but it depends on a specific Eclipse installation layout and is harder to reproduce than Tycho. For new work, Tycho is the better-supported path.
Choosing a route with the same criteria
The comparison below uses consistent criteria: what dependency model each handles, what tooling must exist, whether the output matches IDE behavior, and how reproducible the result is.
| Route | Handles | Tooling needed | Matches IDE compiler | Reproducibility |
|---|---|---|---|---|
| plain javac | ordinary Java, no Eclipse-specific deps | JDK only | No (diagnostics differ) | High |
| ECJ standalone | ordinary Java and Eclipse library jars | JDK plus ECJ jar | Yes (same compiler) | High |
| Ant + JDT adapter | same as ECJ, with a reusable script | JDK, Ant, ECJ jar | Yes | High, given committed files |
| Tycho | OSGi plugins, features, RCP, p2 | JDK, Maven, target definition | Yes, plus bundle resolution | High, but slower first run |
If your code is ordinary Java and you don't need Eclipse's exact diagnostics, plain javac is perfectly adequate and has zero extra dependencies. ECJ earns its place when you need behavior parity with the IDE, when you're compiling against Eclipse libraries without javac, or when you want to catch warnings the IDE shows. Tycho is the only correct choice once MANIFEST.MF is in play.
A worked example, with arithmetic you can reproduce
Suppose you have 1,240 Java files in src/, five dependency jars in libs/, and you're targeting Java 17 on a Linux CI runner. Prepare an argument file so the command line stays short:
Then list source files, one per line, appended by find src -name "*.java" >> compile.args. Run java -jar tools/ecj.jar @compile.args. If the build takes roughly 90 seconds locally and CI runs it once per pull request, the annual compute cost is trivial; the real saving is avoiding a 10-minute IDE reconnect step on every branch. I'd commit compile.args for the file list and generate the classpath segment from a small script, so dependency changes update one place.
A common false failure in this setup: a developer adds a dependency to an Eclipse project's .classpath but not to libs/. Local IDE builds pass; the headless build fails with "cannot find symbol." The fix is to make the headless classpath the source of truth, or to derive it from the project file, so the two can't drift.
Troubleshooting: symptoms, likely causes, reversible checks
Start with the reversible checks before touching configuration. If the build fails only in CI, run the identical command locally first; that isolates environment from code. If it fails only locally, clear the output directory and retry, because stale .class files can mask or fake errors.
"Unsupported class file major version" means your JDK is older than the bytecode of a dependency or your target. Run java -version and javac -version; if they disagree, PATH or JAVA_HOME is pointing at the wrong install, so fix that before anything else. "Package does not exist" for an Eclipse package means the relevant jar isn't on the classpath; check whether the same package exists in the IDE's resolved libraries and copy that jar into libs/. In a Tycho build, "no solution found" for a bundle means the target platform lacks it, so add the repository rather than overriding the bundle.
Stop and get help from someone who knows your build system when errors point at missing platform-specific native libraries, when Tycho fails to resolve the target platform after the declared repositories are verified correct, or when the failure only reproduces on one machine and clearing caches doesn't change it. Those aren't classpath problems you can fix by guessing.
Practical defaults and where they stop working
For a mixed repository, the clean split is Tycho for the plugin and feature modules and ECJ or Ant for any plain Java utilities they depend on. Pin every tool version in the repository, run the build from a clean checkout as part of your checks, and treat the headless build, not the IDE, as the definition of "compiles." That habit catches drift early.
The limits are worth stating plainly. ECJ doesn't replace your dependency manager; you still have to place the right jars on the classpath. Tycho doesn't replace a target definition; it consumes one. Ant doesn't make a fragile build robust; it makes it repeatable. None of these tools will tell you that your IDE and CI disagree about which source folders exist, because that information lives in project files you must keep synchronized. The build succeeds or fails on the files you give it, so give it the same files everywhere.