--release flag
The javac option that compiles for an older Java release, checking against that release's library and writing its class file version.
In more detail
A newer compiler can build class files that an older JVM accepts; --release 17 makes the output load on Java 17. Unlike older options, it also stops you calling library methods that did not exist in that release. Maven sets it through the maven.compiler.release property, and Gradle through a toolchain or release setting.
Examples
javac --release 17 Hello.java<maven.compiler.release>21</maven.compiler.release>Related terms
- class file version — The number stored in every class file that records which Java release it targets, so an older JVM can refuse a file from the future.
- javac — The Java compiler command, which reads .java source files and writes one .class file per class.
- Maven property — A named value in a pom.xml properties block, reused elsewhere in the file as ${name} or read by plugins.
Taught in
- Release Trains And Long Term Support — Modern Java: Virtual Threads & High-Throughput Services
- The Toolchain: Maven — Modern Java: Virtual Threads & High-Throughput Services