views:

1213

answers:

3

Is there an similar property like System.getProperty("java.home") that will return the JDK directory instead of the JRE directory? I've looked http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html#getProperties() and there doesn't seem to be anything for the JDK.

+3  A: 

One route would be to set a system environment variable like "JAVA_HOME" and use that.

It may not be the best solution, but it would work, and this is what other apps which require JDK rather than JRE (like CruiseControl) require you to do when you set them up.

Justin Standard
A: 

An alternative is to define the path to the JDK via a properties file. This can be in addition to the System environment variable to allow an override.

Depending on your use case, you could put this properties file in the home directory or package with your app.

digitalsanctum
+2  A: 

There's not a property similar to java.home for the JDK. There are some rules of thumb that help detect whether the JRE you're running in is part of a JDK. For example, look for "${java.home}/../lib/tools.jar". In other words, in some cases, you might be able to suggest a default, but in general, the user should tell you which JDK to use.

erickson