Skip to main content

JavaInfo

Struct JavaInfo 

Source
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: String

Human-readable name of the Java implementation (e.g., “OpenJDK”).

§version: String

Version string (e.g., “11.0.2”).

§path: PathBuf

Full path to the java executable (or the path originally provided).

§vendor: String

Vendor name (e.g., “Oracle”, “OpenJDK”).

§architecture: String

Architecture (e.g., “64-Bit”, “32-Bit”).

§java_home: PathBuf

The JAVA_HOME directory corresponding to this installation.

Implementations§

Source§

impl JavaInfo

Source

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

pub fn default() -> Self

Creates a default (empty) JavaInfo with all fields set to "UNKNOWN".

This is primarily useful as a placeholder.

Source§

impl JavaInfo

Source

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

pub fn execute_with_error(&self, args: &str) -> Result<(), JavaError>

Executes the Java executable, printing only stderr to the console. Stdout is captured and discarded.

See execute for details.

Source

pub fn execute_with_output(&self, args: &str) -> Result<(), JavaError>

Executes the Java executable, printing only stdout to the console. Stderr is captured and discarded.

See execute for details.

Trait Implementations§

Source§

impl Debug for JavaInfo

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more