#java #jni #active #host #locate #executable

bin+lib java-locator

Locates a Java installation in the host

9 releases

0.1.9 Jan 31, 2025
0.1.8 Oct 31, 2024
0.1.7 May 29, 2024
0.1.5 Jun 19, 2023
0.1.0 Feb 21, 2019

#141 in Development tools

Download history 13301/week @ 2024-10-25 20896/week @ 2024-11-01 30437/week @ 2024-11-08 22730/week @ 2024-11-15 17649/week @ 2024-11-22 19215/week @ 2024-11-29 19710/week @ 2024-12-06 23293/week @ 2024-12-13 17183/week @ 2024-12-20 20352/week @ 2024-12-27 28608/week @ 2025-01-03 24204/week @ 2025-01-10 26232/week @ 2025-01-17 20488/week @ 2025-01-24 16937/week @ 2025-01-31 23431/week @ 2025-02-07

91,252 downloads per month
Used in 49 crates (11 directly)

MIT/Apache

18KB
221 lines

java-locator

crates.io Build

This is a small utility written in Rust.

It locates the active Java installation in the host.

Usage

The utility can be used as a library, or as an executable:

Library

extern crate java_locator;

fn main() -> java_locator::errors::Result<()> {
    let java_home = java_locator::locate_java_home()?;
    let dyn_lib_path = java_locator::locate_jvm_dyn_library()?;
    let libjsig  = java_locator::locate_file("libjsig.so")?;
    
    println!("The java home is {}", java_home);
    println!("The jvm dynamic library path is {}", dyn_lib_path);
    println!("The file libjsig.so is located in {}", libjsig);
    
    Ok(())
}

Executable

Having rust installed, you may install the utility using cargo:

cargo install java-locator --features build-binary

And then, issuing

java-locator

you should have an output like:

/usr/lib/jvm/java-11-openjdk-amd64

You may retrieve the location of the jvm shared library:

java-locator --jvmlib

should give an output like:

/usr/lib/jvm/java-11-openjdk-amd64/lib/server

This may be used in cases when the LD_LIBRARY_PATH (or PATH in windows) should be populated.

You may also retrieve the location of any file inside the Java installation:

java-locator --file libjsig.so

and you can even use wildcards:

java-locator --file libjsig*

The latter two commands should return something like:

/usr/lib/jvm/java-11-openjdk-amd64/lib

Available Features

  • build-binary: Generates a java-locator executable

  • locate-jdk-only: Instructs java-locator to locate only JDKs.

    In a system that has only JREs installed, java-locator will not find any Java installation if this feature is enabled.

    This feature also solves issues when using JDK 8: In usual installations, the symlinks of the java executable in the $PATH lead to the jre directory that lies inside the JDK 8. When $JAVA_HOME is not defined in the system, java-locator attempts to locate the Java installation following the symlinks of the java executable. Having done that, it cannot locate development artifacts like jni.h headers, javac etc. With this feature enabled though, java-locator will locate development artifacts normally.

License

At your option, under:

Dependencies

~0–0.8MB
~15K SLoC