npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@viperproject/locate-java-home

v1.1.16

Published

Locates JAVA_HOME on any platform, and can differentiate between different versions.

Downloads

7,402

Readme

locate-java-home

Locates JAVA_HOME on any platform, and can differentiate between different versions.

Test Status

Usage

npm install @viperproject/locate-java-home
import LocateJavaHome from '@viperproject/locate-java-home'; // or var LocateJavaHome = require('@viperproject/locate-java-home').default;
LocateJavaHome(function(error, javaHomes) {
   javaHomes.forEach(function(homeInfo) {
      console.log("Found Java " + homeInfo.version + " at " + homeInfo.path);
      if (homeInfo.isJDK) {
        console.log("It's a JDK!");
      }
   });
});

// Limit to JDKs for Java 6 and above.
LocateJavaHome({
    // Uses semver :) Note that Java 6 = Java 1.6, Java 8 = Java 1.8, etc.
    version: ">=1.6",
    mustBeJDK: true
}, function(error, javaHomes) {
    // Done.
});

Motivation

I originally wrote this utility for DoppioJVM, which requires access to the Java 8 JDK during build time.

I required the following:

  • The ability to check the version of java in JAVA_HOME.
  • Verify that JAVA_HOME is a JDK and not a JRE.
  • Detect a Java 8 JDK even if it is not the default version of Java installed.
  • Have the above work across Windows, Mac, and Linux.

Since this functionality is likely generally useful, I have decided to release this as a standalone library! Enjoy! :)

API

The locate-java-home package is a single async function that takes an optional options argument:

LocateJavaHome(options, function(error, javaHomes) {});
LocateJavaHome(function(error, javaHomes) {});

javaHomes is an array of objects that contain information about each JAVA_HOME we found:

{
  // Absolute path to JAVA_HOME
  path: string;
  // Version of Java in the JAVA_HOME.
  version: string;
  // Security number of this version of Java.
  // Typically, you want a version with the largest security number.
  // Note: For Java 9 and later, this will always be '0' as this is now
  // encoded into the version number. See http://openjdk.java.net/jeps/223
  // and https://blogs.oracle.com/java-platform-group/a-new-jdk-9-version-string-scheme
  security: number;
  // True if this JAVA_HOME is a JDK, false if it is a JRE.
  isJDK: boolean;
  // Is this version of Java 64-bit?
  is64Bit: boolean;
  // Paths to various executables.
  executables: {
    java: string;
    // JDK only:
    javac: string;
    javap: string;
  }
}

Options

locate-java-home surfaces a number of useful options:

{
  // Semantic versioning string (e.g. ~1.6, >1.6....)
  version: string;
  // Are you specifically looking for a JDK over a JRE?
  mustBeJDK: boolean;
  // Are you specifically looking for a JRE over a JDK?
  mustBeJRE: boolean;
  // Are you specifically looking for a 64-bit JAVA_HOME?
  mustBe64Bit: boolean;
  // Do you want locate-java-home to exit fatally if one of the found JAVA_HOME
  // locations does not function appropriately? (Mainly useful for debugging.)
  paranoid: boolean;
}

Global Script

If you install locate-java-home globally, you'll have access to the locate-java-home command line tool. Currently, it lists all of the JAVA_HOME locations on your system. If there's any desire to expand it into a full-fledged command line tool that exposes the options of this library, let me know!