A collection of Java related utils.
npm i jdk-utils
Find Java runtime from all possible locations on your machine. Covering:
JAVA_HOME
.PATH
.~/.jabba/jdk
~/.gradle/jdk
/usr/local
/opt/homebrew
/home/linuxbrew/.linuxbrew
/usr/lib/jvm
/Library/Java/JavaVirtualMachines
, ~/Library/Java/JavaVirtualMachines
, output of java_home -V
.%ProgramFiles%
and %LocalAppData%
,Note: If you want to skip scanning a certain source for better performance, you can specify skipFrom
options when calling the API.
Below command lists all detected JDKs with details.
npx jdk-utils
require("jdk-utils").findRuntimes().then(console.log)
/*
[{
homedir: '/home/username/.sdkman/candidates/java/17.0.1-ms',
}, {
homedir: '/usr/lib/jvm/java-11-openjdk-amd64',
},
...
]
*/
import { findRuntimes } from "jdk-utils";
await findRuntimes({checkJavac: true, withVersion: true, withTags: true});
/*
[{
homedir: '/home/yanzh/.sdkman/candidates/java/17.0.1-ms',
hasJavac: true,
isFromSDKMAN: true,
version: { java_version: '17.0.1', major: 17 }
}, {
homedir: '/usr/lib/jvm/java-11-openjdk-amd64',
hasJavac: true,
version: { java_version: '11.0.7', major: 11 }
},
...
]
*/