简体   繁体   中英

Find installation directory of JDK in windows

I have an application which dynamically loads jvm.dll, therefore I need to know where the DLL resides. Currently I am trying standard locations like C:\\Program Files\\Java\\jdk...\\jre\\bin\\server\\jvm.dll . However this is quite tedious and error prone (due to version numbers etc.) and a more sophisticated solution would require some intelligence in my application to determine the correct path. In the worst case I end up asking the user to specify where jvm.dll resides.

On Mac OS X there is a method to find the Java Home directory using /usr/libexec/java_home, on Linux I am mostly fine with simply finding out where javac resides and following symlinks. Is there a similarily simple and sufficient method to find the location of a JDK without try-and-error, searching the whole filesystem, or asking the user?

This question is not about configuring my system such that javac is in my path or anything like that. I want to find, programmatically, the location of a JDK (or JRE for that matter) in a typical misconfigured windows system with screwed path variables and poor directory structures.

In windows 7, there is a DOS command that gets you the installation directory of java on the system. Try the below command.

where java

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM