user7128116
user7128116

Reputation:

Can I target an older Java environment than the compiler?

I have built a jar file with the newest JRE. When I try to use it in another computer, I get an error that says that the JRE is older.

Can I build a JAR file that will run on this older version of JRE?

Upvotes: 1

Views: 280

Answers (1)

Timothy Truckle
Timothy Truckle

Reputation: 15624

Yes, you can specify the target Java version at javacs command line:

$ javac -help Usage: javac <options> <source files> where possible options include: ... -source <release> Provide source compatibility with specified release -target <release> Generate class files for specific VM version

This is also supported by build tools like maven and gradle.

But you have to be careful:

This does not check that you don't access classes or methods from the JRE which are not (yet) available in the old version...

Upvotes: 2

Related Questions