Maven "Fork failed ... Cannot run program javac" in CI
The compiler plugin is configured to fork a separate javac process, but the executable is not on PATH or at the configured executable path. The fork fails before any source is compiled.
What this error means
compile fails with "Fatal error compiling: Fork failed: java.io.IOException: Cannot run program \"javac\": error=2, No such file or directory" when <fork>true</fork> is set.
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-compiler-plugin:3.13.0:compile (default-compile) on project app:
Fatal error compiling: Fork failed: java.io.IOException:
Cannot run program "javac": error=2, No such file or directory -> [Help 1]Common causes
Forked compilation with javac not on PATH
With <fork>true</fork>, the plugin launches javac as a child process; if it is not on PATH (JRE, wrong JAVA_HOME), the fork fails.
A wrong <executable> path
A configured <executable> points at a javac that does not exist on the runner.
How to fix it
Provide a JDK so javac is on PATH
Install a JDK and let setup-java fix PATH and JAVA_HOME so the fork finds javac.
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '21'Point the compiler at the real javac
If you must set an explicit executable, use the JDK path that exists on the runner.
<configuration>
<fork>true</fork>
<executable>${env.JAVA_HOME}/bin/javac</executable>
</configuration>How to prevent it
- Run on a JDK with javac on PATH.
- Avoid hard-coded
<executable>paths that vary by runner. - Verify
javac -versionbefore forked compilation.