# locate-java-home

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

Latest version **1.1.2** (published 2018-08-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install locate-java-home
pnpm add locate-java-home
yarn add locate-java-home
bun add locate-java-home
```

Provides the command `locate-java-home`.

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2018-08-22 |
| First published | 2015-10-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 126.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | John Vilk |
| Maintainers | jvilk |

## Links

- npm: https://www.npmjs.com/package/locate-java-home
- Repository: https://github.com/jvilk/locate-java-home
- Homepage: https://github.com/jvilk/locate-java-home#readme
- Issues: https://github.com/jvilk/locate-java-home/issues
- npm.io page: https://npm.io/package/locate-java-home

## Dependencies (2)

- [async](https://npm.io/package/async.md) ^2.6.1
- [semver](https://npm.io/package/semver.md) ^5.5.1

## Recent versions

- 1.1.2 (latest) — 2018-08-22
- 1.1.1 — 2018-02-06
- 1.1.0 — 2018-02-06
- 1.0.1 — 2018-02-06
- 1.0.0 — 2018-02-06
- 0.1.6 — 2016-08-18
- 0.1.5 — 2015-10-21
- 0.1.4 — 2015-10-18
- 0.1.3 — 2015-10-07
- 0.1.2 — 2015-10-07
- 0.1.1 — 2015-10-07
- 0.1.0 — 2015-10-07

## README

# locate-java-home v1.1.2
> Locates `JAVA_HOME` on any platform, and can differentiate between different versions.

[![Build Status](https://travis-ci.org/jvilk/locate-java-home.svg?branch=master)](https://travis-ci.org/jvilk/locate-java-home)
[![Build status](https://ci.appveyor.com/api/projects/status/575e6s02lbpxnh36/branch/master?svg=true)](https://ci.appveyor.com/project/jvilk/locate-java-home/branch/master)

## Usage

    npm install locate-java-home

```js
import LocateJavaHome from 'locate-java-home'; // or var ImportJavaHome = require('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](https://github.com/plamsa-umass/doppio),
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:

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

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

```typescript
{
  // 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:

```typescript
{
  // 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!

---
_Source: https://npm.io/package/locate-java-home · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
