https://github.com/yegor256/jhome
Get JAVA_HOME from Java, even if it's not set
https://github.com/yegor256/jhome
java java-home
Last synced: 11 months ago
JSON representation
Get JAVA_HOME from Java, even if it's not set
- Host: GitHub
- URL: https://github.com/yegor256/jhome
- Owner: yegor256
- License: mit
- Created: 2023-11-20T14:15:37.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2025-03-17T15:13:46.000Z (over 1 year ago)
- Last Synced: 2025-03-22T21:06:35.941Z (over 1 year ago)
- Topics: java, java-home
- Language: Java
- Homepage:
- Size: 168 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Finds Absolute Path of JAVA_HOME in Runtime
[](https://www.elegantobjects.org)
[](https://www.rultor.com/p/yegor256/jhome)
[](https://www.jetbrains.com/idea/)
[](https://github.com/yegor256/jhome/actions/workflows/mvn.yml)
[](https://www.0pdd.com/p?name=yegor256/jhome)
[](https://maven-badges.herokuapp.com/maven-central/com.yegor256/jhome)
[](https://www.javadoc.io/doc/com.yegor256/jhome)
[](https://codecov.io/gh/yegor256/jhome)
[](https://hitsofcode.com/view/github/yegor256/jhome)
[](https://github.com/yegor256/jhome/blob/master/LICENSE.txt)
In your Java application you may want to run another Java application.
In order to do this, you need to know where is the `bin/java` executable.
It's in the `JAVA_HOME` (environment variable), which is not always set.
Instead of looking for this place manually, just use this small one-class
library.
First, you add this to your `pom.xml`:
```xml
com.yegor256
jhome
0.0.5
```
Then, you use it like this:
```java
import com.yegor256.jhome;
Path p = new Jhome().path("bin/java");
```
The result is the location of `bin/java` inside `JAVA_HOME`.
Also, you can use `java()` and `javac()` methods in order to get the full path
to `java` and `javac` executables respectively:
```java
import com.yegor256.jhome;
Path java = new Jhome().java();
Path javac = new Jhome().javac();
```
## How to Contribute
Fork repository, make changes, send us
a [pull request](https://www.yegor256.com/2014/04/15/github-guidelines.html).
We will review your changes and apply them to the `master` branch shortly,
provided they don't violate our quality standards. To avoid frustration,
before sending us your pull request please run full Maven build:
```bash
mvn clean install -Pqulice
```
You will need Maven 3.3+ and Java 8+.