diff --git a/crates/java-bridge/src/node/java.rs b/crates/java-bridge/src/node/java.rs index b77bb05..ba5ca5c 100644 --- a/crates/java-bridge/src/node/java.rs +++ b/crates/java-bridge/src/node/java.rs @@ -38,8 +38,11 @@ pub struct Java { impl Java { /// Create a new JVM instance. /// @param libPath The path to jvm.(dll|so|dylib) - /// @param version The JVM version to use. - /// @param opts The JVM options to use. + /// @param version The JVM version to use + /// @param opts The JVM options to use + /// @param javaOptions additional options to pass to the jvm + /// @param javaLibPath the path to the java library (JavaBridge.jar) + /// @param nativeLibPath the path to the native library (java.*.\[dll|so|dylib]) #[napi(constructor)] pub fn new( lib_path: Option, diff --git a/crates/java-bridge/src/node/java_options.rs b/crates/java-bridge/src/node/java_options.rs index 41990f7..574ac4e 100644 --- a/crates/java-bridge/src/node/java_options.rs +++ b/crates/java-bridge/src/node/java_options.rs @@ -5,7 +5,7 @@ pub struct JavaOptions { /// Additional items to add to the class path. This does allow for wildcard imports /// using glob patterns. If a path is unreadable, an error will be thrown. - /// This behaviour can be changed by setting `ignore_unreadable_class_path_entries` to true. + /// This behavior can be changed by setting `ignore_unreadable_class_path_entries` to true. pub classpath: Option>, /// Whether to ignore unreadable class path entries pub ignore_unreadable_class_path_entries: Option, diff --git a/crates/java-rs/src/java/java_env_wrapper.rs b/crates/java-rs/src/java/java_env_wrapper.rs index d26604e..7e4e3c7 100644 --- a/crates/java-rs/src/java/java_env_wrapper.rs +++ b/crates/java-rs/src/java/java_env_wrapper.rs @@ -476,7 +476,7 @@ impl<'a> JavaEnvWrapper<'a> { .as_ref() .ok_or("The jvm was unset".to_string())? .lock() - .unwrap() + .map_err(|_| "Could not lock mutex".to_string())? .class_loader() .clone() .unwrap(); @@ -518,7 +518,7 @@ impl<'a> JavaEnvWrapper<'a> { .as_ref() .ok_or("The jvm was unset".to_string())? .lock() - .unwrap() + .map_err(|_| "Could not lock mutex".to_string())? .class_loader() .clone() .unwrap(); @@ -1471,7 +1471,7 @@ impl<'a> JavaEnvWrapper<'a> { .as_ref() .ok_or("The jvm was unset".to_string())? .lock() - .unwrap() + .map_err(|_| "Could not lock mutex".to_string())? .class_loader() .as_ref() .unwrap() @@ -1491,7 +1491,7 @@ impl<'a> JavaEnvWrapper<'a> { .as_ref() .ok_or("The jvm was unset".to_string())? .lock() - .unwrap() + .map_err(|_| "Could not lock mutex".to_string())? .set_class_loader(loader); Ok(()) diff --git a/ts-src/java.ts b/ts-src/java.ts index 14e8067..803327a 100644 --- a/ts-src/java.ts +++ b/ts-src/java.ts @@ -86,12 +86,12 @@ export interface JVMOptions extends JavaOptions { * 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 + * Also, it is not possible to restart the jvm after it 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 + * the jvm instance may cause *undefined behavior*, which may or may not * cause the application to crash. Let's not do that. * * @param options the options to use when creating the jvm @@ -104,7 +104,7 @@ export function ensureJvm(options?: JVMOptions): boolean { options?.version, options?.opts, options, - getJavaLibPath(), + getJavaLibPath(options?.isPackagedElectron ?? false), getNativeLibPath(options?.isPackagedElectron ?? false) ); diff --git a/ts-src/nativeLib.ts b/ts-src/nativeLib.ts index e1e9b44..ec1bcc5 100644 --- a/ts-src/nativeLib.ts +++ b/ts-src/nativeLib.ts @@ -91,11 +91,15 @@ export function getNativeLibPath(isPackagedElectron: boolean): string { } } -export function getJavaLibPath(): string { +export function getJavaLibPath(isPackagedElectron: boolean): string { const lib = path.join(__dirname, 'JavaBridge.jar'); if (fs.existsSync(lib) && fs.statSync(lib).isFile()) { - return lib; + if (isPackagedElectron) { + return lib.replace(APP_ASAR_REGEX, APP_ASAR_UNPACKED); + } else { + return lib; + } } else { throw new Error('JavaBridge.jar not found'); }