asela38
asela38

Reputation: 4654

How to detect whether client machine is already has installed version of JRE or not?

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

Answers (2)

Stephen C
Stephen C

Reputation: 719576

It is not possible to tell with absolute certainty if a JRE is already installed:

  • The JRE might be installed in a strange place,
  • It might be installed in a directory that the user cannot access, or
  • It might be installed on a removable drive ... that won't be there when it is needed.

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.

  • Is it the version of Java that the user wants to use?
  • Does it have the latest security fixes?
  • Could it have been "messed with"? Might it have junk certificates in its cert store, or dangerous stuff in the endorsed directory, or worse?

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

Andreas Dolk
Andreas Dolk

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

Related Questions