Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically determine what JDK/JRE's are installed on my box

Is there a standard way to do this? I realize this can be somewhat platform dependent. Our product right now is only supported on Windows - so I suppose that's what I'm interested in right now. The only things I can think of are to either scan the registry or crawl the file system. Scanning the file system seems like it can take a really long time - and the registry can be unreliable. Should I do both? Any other suggestions? I tried to look for an API to do this with no luck.

like image 843
Amir Afghani Avatar asked Jul 27 '09 16:07

Amir Afghani


People also ask

How do I find where JDK is installed?

Open command prompt and enter “java –version”. If installed version number is displayed. 2. On Windows, Java is usually installed in the directory C:/Program Files/Java.

How do you check if I have JDK installed?

Going to a command line and typing java -version can tell us for sure if Java is installed. However, if we see an error message, Java might still be installed – we'll just need to investigate further. Many discussions about using java -version mention the JAVA_HOME environment variable.


2 Answers

System.out.println(System.getProperty("java.version"));

Other properties here

like image 120
Denis Tulskiy Avatar answered Sep 27 '22 19:09

Denis Tulskiy


I would firstly start by looking for the JAVA_HOME environment variable (and possibly JDK_HOME although thats far less common) and then determining what version that is and whether it's a JDK or JRE.

After that check for common instead locations. Find out the system's program files directory (don't just assume it's C:\Program Files even though it is 99.5% of the time) and look for common install locations under that (eg Java).

I wouldn't do an exhaustive search.

It's worth asking: do you really need to find JDKs this way? Can't you just ask the user what JDK he or she wishes to use, possibly suggesting any easy ones you've found already?

like image 27
cletus Avatar answered Sep 27 '22 18:09

cletus