Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compatibility of Jar compiled with newer JDK

I have a maven project using Java 17. The maven-compiler-pugin is set to <release>17</release>.
If I build this project with a newer JDK version (for example 21), will the produced Jar still be runnable with a JRE 17?

like image 321
Robert P Avatar asked Feb 04 '26 15:02

Robert P


1 Answers

Short answer - yes. The release property you're using should cover both the produced class version and the usage of API that is available on Java 17.

There's always a caveat that you may be implicitly relying on some undocumented internal behavior and/or bug fix present in Java 21 that won't be present in Java 17, but those should really be rare cases.

like image 56
Mureinik Avatar answered Feb 06 '26 06:02

Mureinik