1

I'm trying to determine inside an application what is the Java version used to call a JAR.

I saw some solutions talking about System.getProperty(java.version), but what if the user have different versions of Java, and the command is like this:

C:\Absolute\Path\To\Java\1.5\java -jar something.jar

Is there any way to know the real Java version?

Alexis Comte
  • 81
  • 1
  • 6

3 Answers3

3

System.getProperty("java.version") will always give you what version of java is currently running the code that called that statement, no matter how many different versions of java exist on the system.

MadConan
  • 3,749
  • 1
  • 16
  • 27
2

You should use System.getProperty("java.version"). This will give you the version of the currently running JVM as a String, And you can then check for a prefix like 1.5 or 1.6, and you have the version of Java.

Also check this question, and the docs for System.getProperty(...).

Hope this helps.

Community
  • 1
  • 1
Jonas Czech
  • 12,018
  • 6
  • 44
  • 65
0
System.getProperty("java.version")
Waqar
  • 428
  • 4
  • 17