pub struct JavaInfo {
pub name: String,
pub version: String,
pub parsed_version: Option<JavaVersion>,
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: StringRaw version string (e.g., “11.0.2”, “1.8.0_202”).
parsed_version: Option<JavaVersion>Parsed structured version (major/minor/patch). None if parsing failed.
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 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")?;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 matches_version(&self, req: &str) -> bool
pub fn matches_version(&self, req: &str) -> bool
Check whether this installation matches a version requirement.
req supports:
"17"— major version match (any 17.x.x)"17.0"— major.minor match (any 17.0.x)"17.0.2"— exact major.minor.patch match"1.8"— legacy Java 8 notation (equivalent to"8")
The legacy "1." prefix (e.g. "1.8" for Java 8) is automatically
stripped from the requirement before comparison, so both "1.8" and
"8" match Java 8.
Returns false if the version could not be parsed.
§Examples
let info = JavaInfo {
version: "11.0.2".into(),
parsed_version: java_manager::JavaVersion::parse("11.0.2"),
..Default::default()
};
assert!( info.matches_version("11"));
assert!( info.matches_version("11.0"));
assert!( info.matches_version("11.0.2"));
assert!(!info.matches_version("17"));
let java8 = JavaInfo {
version: "1.8.0_202".into(),
parsed_version: java_manager::JavaVersion::parse("1.8.0_202"),
..Default::default()
};
assert!( java8.matches_version("1.8"));
assert!( java8.matches_version("1.8.0"));
assert!( java8.matches_version("8"));Sourcepub fn is_jdk(&self) -> bool
pub fn is_jdk(&self) -> bool
Returns true if this installation is a full JDK (has javac).
Checks for the presence of javac (or javac.exe on Windows) in the
JAVA_HOME/bin directory. A false return typically means a JRE.
§Examples
use java_manager::java_home;
if let Some(java) = java_home() {
if java.is_jdk() {
println!("Full JDK detected");
} else {
println!("JRE only");
}
}Sourcepub fn capabilities(&self) -> Vec<String>
pub fn capabilities(&self) -> Vec<String>
Returns a list of JDK tools available in this installation.
Checks for common tools in JAVA_HOME/bin: javac, javadoc,
javap, jar, jlink, jmod, jpackage, jshell, jconsole,
jcmd, jmap, jstack, jstat, jhsdb, jfr, jwebserver.
Returns an empty Vec if the directory cannot be read.
§Examples
use java_manager::java_home;
if let Some(java) = java_home() {
let tools = java.capabilities();
println!("Available tools: {:?}", tools);
}