Eskibear / node-jdk-utils

A collection of Java related utils.
MIT License
10 stars 5 forks source link

node-jdk-utils

NPM version NPM downloads

A collection of Java related utils.

Installation

npm i jdk-utils

Usage

findJavaRuntime

Find Java runtime from all possible locations on your machine. Covering:

Note: If you want to skip scanning a certain source for better performance, you can specify skipFrom options when calling the API.

CLI

Below command lists all detected JDKs with details.

npx jdk-utils

callback-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 }
  },
...
]
*/