pub struct JavaInfo {
pub name: String,
pub version: String,
pub path: PathBuf,
pub vendor: String,
pub architecture: String,
pub java_home: PathBuf,
}Expand description
Represents a discovered Java installation.
This struct holds metadata about a Java runtime, such as its version,
vendor, architecture, and the location of its java executable and
JAVA_HOME directory.
Fields§
§name: StringHuman-readable name of the Java implementation (e.g., “OpenJDK”).
version: StringVersion string (e.g., “11.0.2”).
path: PathBufFull path to the java executable (or the path originally provided).
vendor: StringVendor name (e.g., “Oracle”, “OpenJDK”).
architecture: StringArchitecture (e.g., “64-Bit”, “32-Bit”).
java_home: PathBufThe JAVA_HOME directory corresponding to this installation.
Implementations§
Source§impl JavaInfo
impl JavaInfo
Sourcepub fn new(path: String) -> Result<Self, JavaError>
pub fn new(path: String) -> Result<Self, JavaError>
Creates a new JavaInfo from a path pointing either to a java executable
or directly to a JAVA_HOME directory.
The path is canonicalized, and if it is an executable, the JAVA_HOME is
located by walking up the directory tree until a bin/java (or java.exe)
is found. Metadata is then extracted from the release file inside
JAVA_HOME, and any missing fields are filled by running java -version.
§Errors
Returns JavaError::InvalidJavaPath if the path does not exist,
or if JAVA_HOME cannot be determined from an executable.
Returns other JavaError variants if I/O or command execution fails.
§Examples
use java_manager::JavaInfo;
let info = JavaInfo::new("/usr/lib/jvm/java-11-openjdk/bin/java".into())?;
println!("Java version: {}", info.version);Source§impl JavaInfo
impl JavaInfo
Sourcepub fn execute(&self, args: &str) -> Result<(), JavaError>
pub fn execute(&self, args: &str) -> Result<(), JavaError>
Executes the Java executable with the given arguments, printing both stdout and stderr to the console.
The argument string is split using shell‑like rules (via shell_words).
The child process’s stdout and stderr are captured and printed line by line
while the process runs.
§Errors
Returns JavaError::IoError if spawning or waiting fails.
Returns JavaError::Other if the argument string cannot be parsed.
Returns JavaError::ExecutionFailed if the Java process exits with a non‑zero status.
§Examples
java.execute("-version")?;