This package helps with running JAR-Files from JavaScript. If no Java is installed on the system, a openJDK version will be installed temporarily.
This package is inspired by njre but adds a few features. First this package has an function which identifies the path of the installed JRE and runs the JAR directly with it. So the JRE gets downloaded only, if no JAVA is installed on the operating system. This helps to reduce the size of the package.
- Install the package:
npm install node-java-connector
- Define a file like
install.js
where you deal with installing the JRE with the following content:
const njb = require("node-java-connector");
njb
.install(8, { type: "jre" })
.then(dir => {})
.catch(err => {
console.log(err);
});
- Add the script to your
package.json
that the JRE gets installed everytime when your package gets installed:
{
...
"scripts": {
"install": "node install.js",
}
...
}
- Use the
executeJar
method with the path to your JAR-file and optional arguments orexecuteClassWithCP
for non-executable JARs.