Skip to content

A utility to find or download Java

License

Notifications You must be signed in to change notification settings

doublekekse/find-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

find-java

find-java helps you to locate a compatible version of Java on the system. It searches within commonly used directories, including:

  • The Java home directory
  • The Minecraft Launcher directory
  • The Minecraft UWP Launcher directory

If no compatible version of Java can be found, it will automatically download the required version of Java.

Installation

npm install @doublekekse/find-java

Usage

import { findJava } from 'find-java';

const javaPath = await findJava(
  // The required Java version
  { min: 17, optimal: 18 },

  // Path where the required version will temporarily be downloaded and extracted to
  'tmp',

  // Path where Java should be installed to
  'java-dir'
);

You can also specify a different Java executable instead of java, like javaw:

const javaPath = await findJava(
  { min: 17, optimal: 18 },
  'tmp',
  'java-dir',
  'javaw'
);

Note that javaw is only available on Windows.

Finally, you can specify a callback function to track the download progress:

const javaPath = await findJava(
  { min: 17, optimal: 18 },
  'tmp',
  'java-dir',
  'java',
  (progress) => {
    console.log(`Downloading Java: ${progress * 100}%`);
  }
);