1

I am implementing GetDown on my application and configure it to embed a JRE to prevent problems of version installed by the users. But I don't find a way to check if the embedded JRE is really the one used, and i can uninstall java on my computer to test it (my employer didn't give me admin access, yay!).

The command System.out.println(System.getProperty("java.version")); show me the java installed on the user's computer, but how can I get what verion of java the application is really using.

Thank you for your answers and sorry for my bad english.

Däñish Shärmà
  • 2,891
  • 2
  • 25
  • 43
Sterio
  • 21
  • 2
  • What ide are you using? – Turtle May 03 '18 at 09:40
  • 1
    Do you have access to a .class file generated? If so, follow this: https://stackoverflow.com/questions/1096148/how-to-check-the-jdk-version-used-to-compile-a-class-file – Andrea May 03 '18 at 09:40
  • The system property `java.version` **does** give you the version of the JVM that you are currently *running* (not of something installed on your system but not currently running). What made you think otherwise? – Erwin Bolwidt May 03 '18 at 09:44
  • A fun fact linked to wha t@Andreaジーティーオー said: if you check the hexa of a .class file, you'll see something like `ca fe ba be 00 00 00 34 `, where 34 is the java version. `cafe babe` is the mark of a java class file. – Turtle May 03 '18 at 09:44
  • The OP is not asking for the version of Java used to compile a class, but is asking for the version of Java that is currently running. – Erwin Bolwidt May 03 '18 at 09:45
  • that command does **not** show you the Java version that is "installed". It shows the version of the JRE that is used to **run** that code - you can't call `System.getProperty()` outside of a running JVM. –  May 03 '18 at 09:55
  • You have provided you own answer since you asked "_how can I get what verion of java the application is really using._" and `System.getProperty("java.version")` provide the version of the JVM executing the code. – AxelH May 03 '18 at 09:56

2 Answers2

2

System.out.println(System.getProperty("java.version")); doesn't show which Java version is installed on the user's computer, since multiple versions can be installed. It shows which Java version the program is currently being executed on.

Chai T. Rex
  • 2,972
  • 1
  • 15
  • 33
  • I don't think so, I use the jre 1.8.0_111 as embedded java, and on another computer when the application call that command, it show me the version 1.8.0_60. – Sterio May 03 '18 at 09:51
  • 2
    because that other computer use "1.8.0_60".. This is the version of the JVM running the compiled code. Which is what you asked "_how can I get what verion of java the application is really using._" – AxelH May 03 '18 at 09:52
  • So my configuration don't work...mmmh that a possibility. – Sterio May 03 '18 at 09:53
  • Check the JDK defined in your IDE (in the project properties in general) and if you run it in command line check the JAVA version with `java -version`. This should show the same result as `System.getProperty` – AxelH May 03 '18 at 09:54
  • My IDE (eclipse neon 2) use JDK 1.8.0_111 installed on m'y computer (thas where I took/duplicate the jre to embed). I will try on a computer without java installed. – Sterio May 03 '18 at 10:03
0

the command System.out.println(System.getProperty("java.version")); give effectively the version used by the application. It was a bad deduction on my part. At the begining I used the JRE 1.8.0_111, but the command returned 1.8.0_60 without reason (I had the problem even on a computer whithout java instaled).

I have tried changing the embedded JRE (using 1.8.0_172) and now the command return 1.8.0_172 . So i assume the problem was from the previous JRE (1.8.0_111).

Thank you for all your answers, they give me tracks to follow.

Sterio
  • 21
  • 2