LeeCambl
LeeCambl

Reputation: 388

Programmatically check whether the Java Development Kit is installed

As part of an installer, I'm building, I want to check whether the Java Development Kit is installed already (specifically the JDK, the JRE will not do). On my local machine, I can clearly see the key in the registry (HKLM\SOFTWARE\JavaSoft\Java Development Kit), but the following code (C#) doesn't find said key:

RegistryKey jdkKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\JavaSoft\Java Development Kit");

When I investigate which keys are present under "HKLM\SOFTWARE\JavaSoft", using the following code, the Java Development Kit is not there.

string[] keyNames = Registry.LocalMachine.OpenSubKey("SOFTWARE\\JavaSoft").GetSubKeyNames();

I've had a look at my environment variables programmatically, too, and nothing there seems to point to the JDK being present either (it is there, as I said above, it's in the registry, and I'm using it for Java development for the program I'm building an installer for, funnily enough).

Any ideas as to how I can determine whether the JDK is installed? As I say, the JRE alone will not suffice, as I'm doing some compilation at runtime, for which I need the JDK.

Upvotes: 0

Views: 2102

Answers (3)

LeeCambl
LeeCambl

Reputation: 388

It appears I was barking up the wrong (registry) tree. I hadn't realised that the registry root is dependent on the configuration platform of my application. Because my app's target platform was set to x86, all searches began in the Wow6432Node of my registry. Changing my target platform to "Any CPU" fixed this, and I can programmatically access all of the trees of my registry as they appear graphically in regedit.

It's possibly worth noting that I was using Visual C# 2010 Express to do this, so changing my target platform had to be done by directly editing the XML of my ".csproj" file, as there are no UI options to do this.

Upvotes: 0

Thorsten Dittmar
Thorsten Dittmar

Reputation: 56727

If you are looking for the Java Development Kit on the machine, you could try to check for the JAVA_HOME environment variable, which usually points to the installation root of the JDK.

string javaHome = Environment.GetEnvironmentVariable("JAVA_HOME");
if (javaHome == null)
    Console.WriteLine("JDK seems not to be present");   

Upvotes: 0

Noomak
Noomak

Reputation: 371

try this

System.out.println(System.getProperty("java.library.path"));

if empty should not be installed

Upvotes: 1

Related Questions