Ensure the java vm is created.
If the jvm is already created, this does nothing.
If the vm is not created yet, the jvm will be created upon this call.
This method is also called every time with no arguments when any call
to the jvm is done in another method.
If you need to set the class path before jvm startup, for example
when using libraries with custom class loaders, you'd need to call
ensureJvmbefore making any other call to java-bridge as those
methods may themselves call ensureJvm with no arguments
(see comment above). Altering the startup classpath after jvm boot is
not possible, you can only alter the runtime classpath using
appendClasspath or appendClasspathAny which may not reflect
in an altered classpath in your java application/library if your
application is using a custom classpath (e.g. Spring Boot).
Also, it is not possible to restart the jvm after is has been started
once, in order to alter the startup classpath. This is due to some
limitations with the destructor feature of the node.js native api,
which may not call the destructor in time and having two jvm instances
in the same application is not allowed by java. Additionally, destroying
the jvm instance may cause undefined behaviour, which may or may not
cause the application to crash. Let's not do that.
Ensure the java vm is created. If the jvm is already created, this does nothing. If the vm is not created yet, the jvm will be created upon this call. This method is also called every time with no arguments when any call to the jvm is done in another method.
Examples
Specify the path to jvm.(dylib|dll|so) manually, specify the java version to use and set to use daemon threads.
Let the plugin find the jvm.(dylib|dll|so)
Let the plugin find the jvm.(dylib|dll|so) and use the default options
Notes on the
classpath
optionIf you need to set the class path before jvm startup, for example when using libraries with custom class loaders, you'd need to call
ensureJvm
before making any other call tojava-bridge
as those methods may themselves callensureJvm
with no arguments (see comment above). Altering the startup classpath after jvm boot is not possible, you can only alter the runtime classpath usingappendClasspath
orappendClasspathAny
which may not reflect in an altered classpath in your java application/library if your application is using a custom classpath (e.g. Spring Boot).Also, it is not possible to restart the jvm after is has been started once, in order to alter the startup classpath. This is due to some limitations with the destructor feature of the node.js native api, which may not call the destructor in time and having two jvm instances in the same application is not allowed by java. Additionally, destroying the jvm instance may cause undefined behaviour, which may or may not cause the application to crash. Let's not do that.