Struct j4rs::JvmBuilder
source · pub struct JvmBuilder<'a> { /* private fields */ }
Expand description
A builder for Jvm
Implementations§
source§impl<'a> JvmBuilder<'a>
impl<'a> JvmBuilder<'a>
sourcepub fn new<'b>() -> JvmBuilder<'b>
pub fn new<'b>() -> JvmBuilder<'b>
Creates a new JvmBuilder.
sourcepub fn classpath_entry(
&'a mut self,
cp_entry: ClasspathEntry<'a>
) -> &'a mut JvmBuilder<'_>
pub fn classpath_entry( &'a mut self, cp_entry: ClasspathEntry<'a> ) -> &'a mut JvmBuilder<'_>
Adds a classpath entry.
sourcepub fn classpath_entries(
&'a mut self,
cp_entries: Vec<ClasspathEntry<'a>>
) -> &'a mut JvmBuilder<'_>
pub fn classpath_entries( &'a mut self, cp_entries: Vec<ClasspathEntry<'a>> ) -> &'a mut JvmBuilder<'_>
Adds classpath entries.
sourcepub fn java_opt(&'a mut self, opt: JavaOpt<'a>) -> &'a mut JvmBuilder<'_>
pub fn java_opt(&'a mut self, opt: JavaOpt<'a>) -> &'a mut JvmBuilder<'_>
Adds a Java option.
sourcepub fn java_opts(&'a mut self, opts: Vec<JavaOpt<'a>>) -> &'a mut JvmBuilder<'_>
pub fn java_opts(&'a mut self, opts: Vec<JavaOpt<'a>>) -> &'a mut JvmBuilder<'_>
Adds Java options.
sourcepub fn with_no_implicit_classpath(&'a mut self) -> &'a mut JvmBuilder<'_>
pub fn with_no_implicit_classpath(&'a mut self) -> &'a mut JvmBuilder<'_>
By default, the created Jvm
s 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.
sourcepub fn detach_thread_on_drop(
&'a mut self,
detach_thread_on_drop: bool
) -> &'a mut JvmBuilder<'_>
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.
sourcepub fn with_native_lib_name(
&'a mut self,
lib_name: &str
) -> &'a mut JvmBuilder<'_>
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.
sourcepub fn skip_setting_native_lib(&'a mut self) -> &'a mut JvmBuilder<'_>
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)
sourcepub fn with_base_path(&'a mut self, base_path: &str) -> &'a mut JvmBuilder<'_>
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.
sourcepub fn with_maven_settings(
&'a mut self,
maven_settings: MavenSettings
) -> &'a mut JvmBuilder<'_>
pub fn with_maven_settings( &'a mut self, maven_settings: MavenSettings ) -> &'a mut JvmBuilder<'_>
Defines the maven settings to use for provisioning maven artifacts.
sourcepub fn with_javafx_support(&'a mut self) -> &'a mut JvmBuilder<'_>
pub fn with_javafx_support(&'a mut self) -> &'a mut JvmBuilder<'_>
Adds JavaFX support to the created JVM
sourcepub fn with_default_classloader(&'a mut self) -> &'a mut JvmBuilder<'_>
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.
sourcepub fn already_initialized() -> Result<Jvm>
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.