java-manager 0.3.0

A Rust library for managing and locating Java installations
Documentation

java-manager

Rust.Crate Crates.io License

Github Author DevState

A comprehensive Rust library and command-line tool for discovering, managing, and interacting with Java installations.


The project is currently under development. All bugs related to the project can be reported by submitting issues on GitHub, and we will regularly fix the reported problems

Features

  • Cross‑platform – Works on Windows, macOS, and Linux/Unix.
  • Java discovery – Find Java installations via PATH, JAVA_HOME, deep system scans (Everything SDK on Windows, walkdir on Linux), or full system scan (registry + keyword BFS + Microsoft Store + where command).
  • Detailed metadata – Extract version, vendor, architecture, and the location of the java executable and JAVA_HOME.
  • Execution control – Run Java programs (JAR or main class) with configurable memory limits, arguments, and I/O redirection.
  • Error handling – Comprehensive error types for path issues, I/O, command execution, and process failures.

Installation

Add this to your Cargo.toml:

[dependencies]

java-manager = "0.2"

Or use the cargo command:

cargo add java-manager

Usage

Locate Java installations

use java_manager::{quick_search, deep_search, full_search, java_home};

// Quick search: look for 'java' in every directory in PATH
let javas = quick_search()?;
for java in javas {
    println!("Found Java at {} (version {})", java.path.display(), java.version);
}

// Deep search: Everything SDK (Windows) or walkdir (Linux)
let all_javas = deep_search()?;

// Full search: multiple scanners without external dependencies
let all_javas = full_search()?;

// Check JAVA_HOME environment variable
if let Some(java) = java_home() {
    println!("JAVA_HOME points to Java version {}", java.version);
}

Execute a Java program

use java_manager::{JavaRunner, JavaRedirect};

let java = java_home().expect("JAVA_HOME not set");

// Run a JAR file
JavaRunner::new()
    .java(java.clone())
    .jar("myapp.jar")
    .min_memory(256 * 1024 * 1024)   // 256 MB
    .max_memory(1024 * 1024 * 1024)  // 1 GB
    .arg("--server")
    .redirect(JavaRedirect::new().output("out.log").error("err.log"))
    .execute()?;

// Or run a main class
JavaRunner::new()
    .java(java)
    .main_class("com.example.Main")
    .arg("arg1")
    .arg("arg2")
    .execute()?;

Get metadata from a specific Java path

use java_manager::JavaInfo;

let info = JavaInfo::new("/usr/lib/jvm/java-11-openjdk/bin/java".into())?;
println!("Name: {}", info.name);
println!("Version: {}", info.version);
println!("Vendor: {}", info.vendor);
println!("Architecture: {}", info.architecture);
println!("JAVA_HOME: {}", info.java_home.display());

Platform Notes

Three search functions serve different needs:

  • quick_search() — Walks PATH on all platforms. Fastest, catches the default Java.
  • deep_search() — Windows: Everything SDK (Everything must be installed + running). Linux: same as full_search().
  • full_search() — No external dependencies. Windows: registry + keyword BFS + Microsoft Store + where command. Linux: walks common directories + ~/.minecraft/runtime with keyword filtering.
  • macOS: Currently supports the same methods as Linux (will be enhanced).

License

This project is licensed under the MIT License. See the LICENSE file for details.