Skip to main content

locate_java_home

Function locate_java_home 

Source
pub fn locate_java_home() -> Result<String>
Expand description

Locates and returns the Java home directory path.

This function first checks the JAVA_HOME environment variable. If not set or empty, it attempts to locate Java using platform-specific methods.

§Platform-specific Behavior

  • Windows: Uses the where command to find java.exe
  • macOS: Uses /usr/libexec/java_home system utility
  • Linux/Unix: Uses the which command to find java

§Returns

  • Ok(String) containing the Java home path
  • Err(JavaLocatorError) if Java cannot be located

§Errors

This function may return an error if:

  • Java is not installed
  • Java is not in the system PATH
  • The platform-specific command fails

§Examples

use java_manager;

fn main() -> java_manager::Result<()> {
    let java_home = java_manager::locate_java_home()?;
    println!("Java home: {}", java_home);
    Ok(())
}