jdk-utils
v0.7.0
Published
JDK related utils for Java related development.
Downloads
4,686
Readme
node-jdk-utils
A collection of Java related utils.
Installation
npm i jdk-utilsUsage
findJavaRuntime
Find Java runtime from all possible locations on your machine. Covering:
JAVA_HOME.- JDK-like paths from
PATH. - SDKMAN installation location.
- jabba installation location, i.e.
~/.jabba/jdk - JBang installation location, i.e.
~/.jbang/cache/jdks - ASDF installation location.
- mise installation location, i.e.
~/.local/share/mise/installs/java. - JDK installations managed by Gradle, e.g.
~/.gradle/jdk - Links specified in jEnv.
- Homebrew installation:
- macOS Intel:
/usr/local - macOS Apple Silicon:
/opt/homebrew - Linux:
/home/linuxbrew/.linuxbrew
- macOS Intel:
- Platform-specific conventional installation location:
- Linux:
/usr/lib/jvm - macOS:
/Library/Java/JavaVirtualMachines,~/Library/Java/JavaVirtualMachines, output ofjava_home -V. - Windows: JDK-like folders under
%ProgramFiles%and%LocalAppData%,
- Linux:
Note: If you want to skip scanning a certain source for better performance, you can specify skipFrom options when calling the API.
If you want to extend coverage without waiting for a new release, pass additionalLocations when calling the API. Each entry is a parent folder of possible Java Homes (not a Java Home itself); the lookup is shallow (direct subdirectories only).
import { findRuntimes } from "jdk-utils";
await findRuntimes({ additionalLocations: ["/opt/my-jdks"] });CLI
Below command lists all detected JDKs with details.
npx jdk-utilscallback-style
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',
},
...
]
*/promise-style
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 }
},
...
]
*/