JAVA_HOMEon any platform, and can differentiate between different versions.
npm install locate-java-home
; // or var ImportJavaHome = require('locate-java-home').default;;// Limit to JDKs for Java 6 and above.;
I originally wrote this utility for DoppioJVM, which requires access to the Java 8 JDK during build time.
I required the following:
- The ability to check the version of
- Verify that
JAVA_HOMEis a JDK and not a JRE.
- Detect a Java 8 JDK even if it is not the default version of Java installed.
- Have the above work across Windows, Mac, and Linux.
Since this functionality is likely generally useful, I have decided to release this as a standalone library! Enjoy! :)
locate-java-home package is a single async function that takes an optional options argument:
javaHomes is an array of objects that contain information about each
JAVA_HOME we found:
locate-java-home surfaces a number of useful options:
If you install
locate-java-home globally, you'll have access to the
line tool. Currently, it lists all of the
JAVA_HOME locations on your system. If there's any
desire to expand it into a full-fledged command line tool that exposes the options of this
library, let me know!