Reputation: 4654
In an application we provide the capability of client for choosing downloading our application with a JRE or not. IF it is possible to detect whether client system is already configured with a JRE or not, it is possible to provide this feature more user friendly mannaer.
Upvotes: 2
Views: 802
Reputation: 719576
It is not possible to tell with absolute certainty if a JRE is already installed:
Searching the entire directory tree is slow, and won't necessarily find anything. The user may get rather impatient ...
Even if you do find a JRE, it is not clear that you should use it without the user's say-so.
Probably the safest thing is to just look at the user's PATH. If there is a JRE on the path, it is a safe bet that the user (or his system administrator) put it there.
Upvotes: 1
Reputation: 114817
If you want to limit your test to check if a JRE is installed and on the path, simply check the environment variable PATH
(System.getEnv()
). You should find the substring bin/java
or bin\java
, depending on the OS.
Or use Runtime.exec
to call java -version
and check the result: it's either the version number or an error message.
Otherwise you'll may have to look at every folder on the target machine (if you want to present all useable JRE/JDK).
Based on Vladimirs comment - If you're not sure, if a JRE is already installed and you want to provide a non-Java based installer, you'll have to choose (or name) the other scripting language or installer that you want to use. The installer will be OS dependant, iaw you'll have to write different ones for all supported operating systems.
With windows you can have a look at the registry for all registered JREs or check the standard folder (C:\Program Files\Java). But a general approach still requires inspecting all (or a subset of all) folders on the target machine. This takes time and may not be very user friendly.
Upvotes: 1