locate-java-home v1.1.2
Locates JAVA_HOME
on any platform, and can differentiate between different versions.
Usage
npm install locate-java-home
import LocateJavaHome from 'locate-java-home';
LocateJavaHome(function(error, javaHomes) {
javaHomes.forEach(function(homeInfo) {
console.log("Found Java " + homeInfo.version + " at " + homeInfo.path);
if (homeInfo.isJDK) {
console.log("It's a JDK!");
}
});
});
LocateJavaHome({
version: ">=1.6",
mustBeJDK: true
}, function(error, javaHomes) {
});
Motivation
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
java
in JAVA_HOME
. - Verify that
JAVA_HOME
is 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! :)
API
The locate-java-home
package is a single async function that takes an optional options argument:
LocateJavaHome(options, function(error, javaHomes) {});
LocateJavaHome(function(error, javaHomes) {});
javaHomes
is an array of objects that contain information about each JAVA_HOME
we found:
{
path: string;
version: string;
security: number;
isJDK: boolean;
is64Bit: boolean;
executables: {
java: string;
javac: string;
javap: string;
}
}
Options
locate-java-home
surfaces a number of useful options:
{
version: string;
mustBeJDK: boolean;
mustBeJRE: boolean;
mustBe64Bit: boolean;
paranoid: boolean;
}
Global Script
If you install locate-java-home
globally, you'll have access to the locate-java-home
command
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!