pub struct JavaInfo {
pub name: String,
pub path: String,
pub version: String,
pub architecture: String,
pub suppliers: String,
}Expand description
Represents detailed information about a Java installation.
This struct contains all relevant information about a Java installation, including version, architecture, supplier, and path information.
§Fields
name: The name of the Java executable (e.g., “java”, “javac”)path: Full path to the Java executableversion: Java version string (e.g., “11.0.12”, “1.8.0_312”)architecture: Architecture information (e.g., “64-bit”, “32-bit”)suppliers: Java supplier/vendor (e.g., “OpenJDK”, “Oracle”)
§Examples
use java_manager::JavaInfo;
// Create a JavaInfo instance
let java_info = JavaInfo::new(
"java",
"/usr/bin/java",
"11.0.12",
"64-bit",
"OpenJDK"
);
println!("Java Info: {}", java_info);
println!("Major version: {:?}", java_info.get_major_version());Fields§
§name: StringName of the Java executable
path: StringFull path to the Java executable
version: StringJava version string
architecture: StringArchitecture (32-bit or 64-bit)
suppliers: StringJava supplier/vendor
Implementations§
Source§impl JavaInfo
impl JavaInfo
Sourcepub fn new(
name: &str,
path: &str,
version: &str,
architecture: &str,
suppliers: &str,
) -> Self
pub fn new( name: &str, path: &str, version: &str, architecture: &str, suppliers: &str, ) -> Self
Creates a new JavaInfo instance.
§Arguments
name- Name of the Java executablepath- Full path to the Java executableversion- Java version stringarchitecture- Architecture informationsuppliers- Java supplier/vendor
§Returns
A new JavaInfo instance
§Examples
use java_manager::JavaInfo;
let info = JavaInfo::new(
"java",
"/usr/bin/java",
"11.0.12",
"64-bit",
"OpenJDK"
);Sourcepub fn execute(&self, args: &[&str]) -> Result<Child>
pub fn execute(&self, args: &[&str]) -> Result<Child>
Executes a Java command asynchronously.
This method spawns a new process and returns immediately without waiting for the command to complete.
§Arguments
args- Command-line arguments to pass to Java
§Returns
Ok(Child)- A handle to the child processErr(std::io::Error)- If the process cannot be spawned
§Examples
use java_manager::JavaInfo;
let info = JavaInfo::new("java", "/usr/bin/java", "11.0.12", "64-bit", "OpenJDK");
let child = info.execute(&["-version"]);
if let Ok(mut child) = child {
let _ = child.wait();
}Sourcepub fn execute_and_wait(&self, args: &[&str]) -> Result<Output>
pub fn execute_and_wait(&self, args: &[&str]) -> Result<Output>
Executes a Java command and waits for completion.
This method runs the command and waits for it to complete, returning the exit status and output.
§Arguments
args- Command-line arguments to pass to Java
§Returns
Ok(Output)- Command output including status, stdout, and stderrErr(std::io::Error)- If the command fails to execute
§Examples
use java_manager::JavaInfo;
let info = JavaInfo::new("java", "/usr/bin/java", "11.0.12", "64-bit", "OpenJDK");
let output = info.execute_and_wait(&["-version"]);
if let Ok(output) = output {
println!("Exit status: {}", output.status);
}Sourcepub fn execute_with_output(&self, args: &[&str]) -> Result<String>
pub fn execute_with_output(&self, args: &[&str]) -> Result<String>
Executes a Java command and returns the output as a string.
This method captures both stdout and stderr, returning them as a string. If the command succeeds, stdout is returned. If it fails, stderr is returned.
§Arguments
args- Command-line arguments to pass to Java
§Returns
Ok(String)- Command output as a stringErr(std::io::Error)- If the command fails to execute
§Examples
use java_manager::JavaInfo;
fn main() -> std::io::Result<()> {
let info = JavaInfo::new("java", "/usr/bin/java", "11.0.12", "64-bit", "OpenJDK");
let output = info.execute_with_output(&["-version"])?;
println!("Java version:\n{}", output);
Ok(())
}Sourcepub fn execute_with_separate_output(
&self,
args: &[&str],
) -> Result<(String, String)>
pub fn execute_with_separate_output( &self, args: &[&str], ) -> Result<(String, String)>
Executes a Java command and returns both stdout and stderr as separate strings.
§Arguments
args- Command-line arguments to pass to Java
§Returns
Ok((String, String))- Tuple containing (stdout, stderr)Err(std::io::Error)- If the command fails to execute
§Examples
use java_manager::JavaInfo;
fn main() -> std::io::Result<()> {
let info = JavaInfo::new("java", "/usr/bin/java", "11.0.12", "64-bit", "OpenJDK");
let (stdout, stderr) = info.execute_with_separate_output(&["-version"])?;
println!("Stdout:\n{}", stdout);
println!("Stderr:\n{}", stderr);
Ok(())
}Sourcepub fn get_major_version(&self) -> Option<u32>
pub fn get_major_version(&self) -> Option<u32>
Returns the major version number of Java.
Parses the version string to extract the major version. Handles both old (1.8) and new (9+) version formats.
§Returns
Some(u32)- Major version numberNone- If version cannot be parsed
§Examples
use java_manager::JavaInfo;
let info1 = JavaInfo::new("java", "/usr/bin/java", "1.8.0_312", "64-bit", "OpenJDK");
assert_eq!(info1.get_major_version(), Some(8));
let info2 = JavaInfo::new("java", "/usr/bin/java", "11.0.12", "64-bit", "OpenJDK");
assert_eq!(info2.get_major_version(), Some(11));Sourcepub fn is_at_least_version(&self, min_version: u32) -> bool
pub fn is_at_least_version(&self, min_version: u32) -> bool
Checks if the Java version is at least the specified minimum version.
§Arguments
min_version- Minimum major version required
§Returns
trueif Java version >= min_versionfalseif Java version < min_version or version cannot be parsed
§Examples
use java_manager::JavaInfo;
let info = JavaInfo::new("java", "/usr/bin/java", "11.0.12", "64-bit", "OpenJDK");
assert!(info.is_at_least_version(8)); // Java 11 >= 8
assert!(info.is_at_least_version(11)); // Java 11 >= 11
assert!(!info.is_at_least_version(17)); // Java 11 < 17Sourcepub fn get_java_home(&self) -> String
pub fn get_java_home(&self) -> String
Extracts the Java home directory from the executable path.
Removes the “bin” directory from the path to get the JAVA_HOME.
§Returns
Java home directory path
§Examples
use java_manager::JavaInfo;
let info = JavaInfo::new("java", "/usr/lib/jvm/java-11-openjdk/bin/java", "11.0.12", "64-bit", "OpenJDK");
assert_eq!(info.get_java_home(), "/usr/lib/jvm/java-11-openjdk");Sourcepub fn to_display_string(&self) -> String
pub fn to_display_string(&self) -> String
Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Validates that the Java executable exists and is executable.
§Returns
trueif the executable exists and is accessiblefalseotherwise
§Examples
use java_manager::JavaInfo;
let info = JavaInfo::new("java", "/usr/bin/java", "11.0.12", "64-bit", "OpenJDK");
if info.is_valid() {
println!("Java installation is valid");
}