Can I discover a version of Java from my native C ++ language

I am writing a complex install / install application in my native C ++ / MFC. I would very much like to be able to detect the version of Java that has been installed (if any).

Is this possible, and so how?

+4
source share
4 answers

You can try running java -version in a subprocess (reading this output from the process with pipe) and analyzing the results (if any); or you may come across a Windows registry (which feels even more complex, but may be less kludgy).

+1
source

Run the process that runs the following command: java -version . Gather the conclusion and analyze it. It looks something like this:

 java version "1.5.0_16" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-284) Java HotSpot(TM) Client VM (build 1.5.0_16-133, mixed mode, sharing) 

This is written to stderr. You need to collect the output of stderr and analyze it.

+3
source

I would suggest using the registry. You program windows, so do it differently. The registry is an irrational concern.

Registry key for version:

 HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\CurrentVersion 

Information on how to get the value from the registry can be found here .

Information about other java-related registry keys can be found here .

+2
source

Keep in mind also that it is entirely possible that several JREs are installed on the machine at the same time. If your installer detects multiple JREs, it should offer the user a choice, and not assume that one of them (for example, the last one) should be the one that will be used by your application.

+1
source

All Articles