User Tools

Site Tools


java_versioning

Java Versioning

If you want to deploy .class files and your target system is using an older version of Java, you can specify the target version when you compile. For example, if your development machine has Java 21 and your target machine has Java 17, you'd compile like this:

javac -source 17 -target 17 Main.java

When you compile, you may see a message similar to this:

warning: [options] system modules path not set in conjunction with -source 17

If so, you can also use Java's –release argument which combines the -source and -target arguments and automatically sets the modules path:

javac --release 17 Main.java

With either of these options, you'll see that the version has been set:

file Main.class

Main.class: compiled Java class data, version 61.0 (Java SE 17)

java_versioning.txt · Last modified: 2024/10/03 05:22 by jimc