Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions crates/java-bridge/src/node/java.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
Expand Down
2 changes: 1 addition & 1 deletion crates/java-bridge/src/node/java_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<String>>,
/// Whether to ignore unreadable class path entries
pub ignore_unreadable_class_path_entries: Option<bool>,
Expand Down
8 changes: 4 additions & 4 deletions crates/java-rs/src/java/java_env_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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()
Expand All @@ -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(())
Expand Down
6 changes: 3 additions & 3 deletions ts-src/java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -104,7 +104,7 @@ export function ensureJvm(options?: JVMOptions): boolean {
options?.version,
options?.opts,
options,
getJavaLibPath(),
getJavaLibPath(options?.isPackagedElectron ?? false),
getNativeLibPath(options?.isPackagedElectron ?? false)
);

Expand Down
8 changes: 6 additions & 2 deletions ts-src/nativeLib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
Loading