Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check JRE version prior to launch?

What's the best way to determine if the version of the JRE installed on a machine is high enough for the application which the user wants to run? Is there a way of doing it using java-only stuff? I'd like the solution to work on Windows/Linux/MacOSX - if the JRE version is too low a message should be displayed. Currently I'm getting an exception if i try to run it on Java 1.5 (the app is built for Java 1.6). If there's no universal solution, what's the best way to do it on Windows?

like image 974
Vladimir Prenner Avatar asked Oct 21 '08 14:10

Vladimir Prenner


People also ask

Is JRE pre installed on my computer?

In the Search bar, type Control Panel. Click Programs. If the Java icon present, then Java is installed. If not, click Programs and Features, and look for installed versions of Java in the J's.

Which Java JRE version should I use?

Java SE 11 OR 17 remains the preferred production standard in 2022. While both 9 and 10 have been released, neither will be offering LTS. Since it's first release in 1996, Java has maintained a reputation for being one of the most secure, reliable, and platform independent languages for computer programming.

How do I find JRE path in Windows?

C:\Program Files\Java\jre<version>


1 Answers

You could do this using reflection and two compilers. Compile a main class with the oldest java version you want to be able to run at all with. It checks the version using System.getProperty("java.version"), or whatever, and then uses reflection to load your real main class if that check passes, possibly even loading the jar directly. The JRE shouldn't load any classes that weren't referenced by your outer main class at compile time.

like image 70
TREE Avatar answered Sep 18 '22 18:09

TREE