1

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?

Toby Speight
  • 27,591
  • 48
  • 66
  • 103
  • Possible duplicate of [Can newer JRE versions run Java programs compiled with older JDK versions?](https://stackoverflow.com/questions/10895969/can-newer-jre-versions-run-java-programs-compiled-with-older-jdk-versions) – Pieter Dec 14 '17 at 11:35
  • Other way around I think, @Pieter - can you compile with a new JDK to target an older JRE. – Toby Speight Dec 14 '17 at 11:37

1 Answers1

2

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...

Timothy Truckle
  • 15,071
  • 2
  • 27
  • 51