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,661
  • 1
  • 15
  • 26
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
JonasCz
  • 11,660
  • 6
  • 43
  • 64
0
System.getProperty("java.version")
Waqar
  • 430
  • 3
  • 17