Function ensureJvm

  • 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.

    import { ensureJvm, JavaVersion } from 'java-bridge';

    ensureJvm({
    libPath: 'path/to/jvm.dll',
    version: JavaVersion.VER_9,
    });

    Let the plugin find the jvm.(dylib|dll|so)

    ensureJvm({
    version: JavaVersion.VER_9,
    });

    Let the plugin find the jvm.(dylib|dll|so) and use the default options

    ensureJvm();
    

    Notes on the classpath option

    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 ensureJvm before 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.

    Parameters

    • Optional options: JVMOptions

      the options to use when creating the jvm

    Returns boolean

    true if the jvm was created and false if the jvm already existed and was not created

Generated using TypeDoc