How can I find the location of the JDK directory in Java?

Is there a similar property like System.getProperty ("java.home") that will return the JDK directory instead of the JRE directory? I took a look at http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html#getProperties () and nothing seems to exist for the JDK.

+1


source to share


3 answers


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



It may not be the best solution, but it will work and it will require other applications that require a JDK rather than a JRE (like CruiseControl) when you configure them.

+3


source


There is no java.home

JDK- like property . There are some rules of thumb that can help you determine if the JRE you are working in is part of the JDK. For example, search for "$ {java.home} /../ lib / tools.jar". In other words, in some cases you can suggest the default, but in general the user has to tell you which JDK to use.



+2


source


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

Depending on your use case, you can place this properties file in your home directory or package with your application.

0


source







All Articles