Struct j4rs::JvmBuilder

source ·
pub struct JvmBuilder<'a> { /* private fields */ }
Expand description

A builder for Jvm

Implementations§

source§

impl<'a> JvmBuilder<'a>

source

pub fn new<'b>() -> JvmBuilder<'b>

Creates a new JvmBuilder.

source

pub fn classpath_entry( &'a mut self, cp_entry: ClasspathEntry<'a> ) -> &'a mut JvmBuilder<'_>

Adds a classpath entry.

source

pub fn classpath_entries( &'a mut self, cp_entries: Vec<ClasspathEntry<'a>> ) -> &'a mut JvmBuilder<'_>

Adds classpath entries.

source

pub fn java_opt(&'a mut self, opt: JavaOpt<'a>) -> &'a mut JvmBuilder<'_>

Adds a Java option.

source

pub fn java_opts(&'a mut self, opts: Vec<JavaOpt<'a>>) -> &'a mut JvmBuilder<'_>

Adds Java options.

source

pub fn with_no_implicit_classpath(&'a mut self) -> &'a mut JvmBuilder<'_>

By default, the created Jvms include an implicit classpath entry that includes the j4rs jar. When with_no_implicit_classpath() is called, this classpath will not be added to the Jvm.

source

pub fn detach_thread_on_drop( &'a mut self, detach_thread_on_drop: bool ) -> &'a mut JvmBuilder<'_>

When a Jvm goes out of scope and is being dropped, its current thread is being detached from the Java VM. A Jvm that is created with detach_thread_on_drop(false) will not detach the thread when being dropped.

This is useful when in the Java world a native method is called and in the native code someone needs to create a j4rs Jvm. If that Jvm detaches its current thread when being dropped, there will be problems for the Java world code to continue executing.

source

pub fn with_native_lib_name( &'a mut self, lib_name: &str ) -> &'a mut JvmBuilder<'_>

In the case that the j4rs is statically linked to some other library, the Java world (j4rs.jar) needs to load that library instead of the default one.

This function defines the native library name to load.

source

pub fn skip_setting_native_lib(&'a mut self) -> &'a mut JvmBuilder<'_>

Instructs the builder not to instruct the Java world j4rs code not to load the native library. (most probably because it is already loaded)

source

pub fn with_base_path(&'a mut self, base_path: &str) -> &'a mut JvmBuilder<'_>

Defines the location of the jassets and deps directory. The jassets contains the j4rs jar and the deps the j4rs dynamic library.

source

pub fn with_maven_settings( &'a mut self, maven_settings: MavenSettings ) -> &'a mut JvmBuilder<'_>

Defines the maven settings to use for provisioning maven artifacts.

source

pub fn with_javafx_support(&'a mut self) -> &'a mut JvmBuilder<'_>

Adds JavaFX support to the created JVM

source

pub fn with_default_classloader(&'a mut self) -> &'a mut JvmBuilder<'_>

j4rs uses a custom ClassLoader (namely the J4rsClassLoader), that allows adding jars to the classpath during runtime, after the underlying JVM is initialized.

This function instructs the builder not to use this custom classloader, but use the default one.

Please note that the J4rsClassLoader needs Java 9 or higher. If you use an older Java version, you must call this function in order for j4rs to work.

If not, you will get exceptions like the following:

java.lang.NoSuchMethodError: java.net.URLClassLoader.(Ljava/lang/String;[Ljava/net/URL;Ljava/lang/ClassLoader;)V

source

pub fn build(&mut self) -> Result<Jvm>

Creates a Jvm

source

pub fn already_initialized() -> Result<Jvm>

Creates a Jvm, similar with an already created j4rs Jvm.

Note: The already created Jvm is a j4rs Jvm, not a Java VM.

Auto Trait Implementations§

§

impl<'a> Freeze for JvmBuilder<'a>

§

impl<'a> RefUnwindSafe for JvmBuilder<'a>

§

impl<'a> Send for JvmBuilder<'a>

§

impl<'a> Sync for JvmBuilder<'a>

§

impl<'a> Unpin for JvmBuilder<'a>

§

impl<'a> UnwindSafe for JvmBuilder<'a>

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, 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>,

§

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>,

§

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.