javac Command: Compile Java in CI
javac compiles Java source files (.java) into bytecode class files (.class).
javac is the reference Java compiler shipped with the JDK. Maven and Gradle invoke it under the hood, but it appears directly in lightweight CI scripts and Docker images. Its flags control output location, classpath, and target bytecode version.
Common flags
-d DIR- write generated .class files to DIR-cp/-classpath PATH- set the user class path for dependencies--release 17- compile against a specific Java release (preferred over -source/-target)-source 17/-target 17- set source and bytecode versions-Xlint:all- enable all recommended warnings-Werror- terminate compilation if any warnings occur@argfile- read options and file names from a file (avoids long command lines)
Example in CI
Compile all sources to a build directory with a pinned release and strict warnings:
shell
javac --release 17 -Xlint:all -Werror -d build/classes -cp "libs/*" $(find src -name "*.java")Common errors in CI
- error: package com.example does not exist - missing dependency on the classpath
- error: cannot find symbol - typo, missing import, or unbuilt dependency
- error: invalid target release: 21 - JDK is older than the requested release
- error: class file has wrong version 61.0, should be 52.0 - bytecode/JDK mismatch
Key takeaways
-dcontrols output location;-cpwires in dependencies.- Prefer
--release Nover-source/-targetto avoid bootclasspath mismatches. - Most CI failures are missing-classpath "package does not exist" / "cannot find symbol".
Related guides
java Command: Run JARs & Classes in CIjava launches the JVM to run classes and JARs. Reference for -jar, -cp, --module-path, -D system properties,…
mvn Command: Build Maven Projects in CImvn is the Maven build tool. Reference for clean, install, verify, -B, -DskipTests, -P, -pl, and the Maven CI…
gradle Command: Build JVM Projects in CIgradle is the JVM build tool. Reference for build, test, --no-daemon, --build-cache, -x, --stacktrace, and th…