2

I need to run a Java application from my application (Java too), but I need to be able to evaluate the Java version to use. The application I need to run requires Java 1.7+ but not all are fully compatible so I would like to be able to use the most appropriate Java version that is installed in this order:

 String preferredJavaPath;

 if (Java 1.8 is installed) {
    preferredJavaPath = Java 1.8 Path
 } else if (Java 1.7 is installed) {
    preferredJavaPath = Java 1.7 Path
 } else {
    preferredJavaPath = current version running.
 }

 if (preferredJavaPath < 1.7) {
    Show warning message.
 }

 Run APP2 using "preferredJavaPath"

I am currently using System.getProperty("java.home") to get the location of the Java version by default (current version).

I need it to work on both Windows and Linux and MacOS.

I have been researching on the internet but the majority refers only to Windows and with not very good results.

Manuel23
  • 175
  • 1
  • 1
  • 11
  • 1
    There is no guaranteed way to do it. Especially on Linux. But see this question for some possible tricks: https://stackoverflow.com/q/6493856/3920048 – Misha Jul 05 '18 at 19:21

1 Answers1

2
System.getProperty("java.version")
LeoDog896
  • 369
  • 5
  • 11
  • That only returns the current version, not all installed versions. See the pseudocode of my publication. I need to find if Java 1.8 is installed, if so, obtain its location, if not, look for Java 1.7, if it exists, obtain its location and if neither exists, just use the current version. – Manuel23 Jul 05 '18 at 19:16