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
wherecommand to findjava.exe - macOS: Uses
/usr/libexec/java_homesystem utility - Linux/Unix: Uses the
whichcommand to findjava
§Returns
Ok(String)containing the Java home pathErr(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(())
}