File tree Expand file tree Collapse file tree 5 files changed +19
-12
lines changed
Expand file tree Collapse file tree 5 files changed +19
-12
lines changed Original file line number Diff line number Diff line change @@ -38,8 +38,11 @@ pub struct Java {
3838impl Java {
3939 /// Create a new JVM instance.
4040 /// @param libPath The path to jvm.(dll|so|dylib)
41- /// @param version The JVM version to use.
42- /// @param opts The JVM options to use.
41+ /// @param version The JVM version to use
42+ /// @param opts The JVM options to use
43+ /// @param javaOptions additional options to pass to the jvm
44+ /// @param javaLibPath the path to the java library (JavaBridge.jar)
45+ /// @param nativeLibPath the path to the native library (java.*.\[dll|so|dylib])
4346 #[ napi( constructor) ]
4447 pub fn new (
4548 lib_path : Option < String > ,
Original file line number Diff line number Diff line change 55pub struct JavaOptions {
66 /// Additional items to add to the class path. This does allow for wildcard imports
77 /// using glob patterns. If a path is unreadable, an error will be thrown.
8- /// This behaviour can be changed by setting `ignore_unreadable_class_path_entries` to true.
8+ /// This behavior can be changed by setting `ignore_unreadable_class_path_entries` to true.
99 pub classpath : Option < Vec < String > > ,
1010 /// Whether to ignore unreadable class path entries
1111 pub ignore_unreadable_class_path_entries : Option < bool > ,
Original file line number Diff line number Diff line change @@ -476,7 +476,7 @@ impl<'a> JavaEnvWrapper<'a> {
476476 . as_ref ( )
477477 . ok_or ( "The jvm was unset" . to_string ( ) ) ?
478478 . lock ( )
479- . unwrap ( )
479+ . map_err ( |_| "Could not lock mutex" . to_string ( ) ) ?
480480 . class_loader ( )
481481 . clone ( )
482482 . unwrap ( ) ;
@@ -518,7 +518,7 @@ impl<'a> JavaEnvWrapper<'a> {
518518 . as_ref ( )
519519 . ok_or ( "The jvm was unset" . to_string ( ) ) ?
520520 . lock ( )
521- . unwrap ( )
521+ . map_err ( |_| "Could not lock mutex" . to_string ( ) ) ?
522522 . class_loader ( )
523523 . clone ( )
524524 . unwrap ( ) ;
@@ -1471,7 +1471,7 @@ impl<'a> JavaEnvWrapper<'a> {
14711471 . as_ref ( )
14721472 . ok_or ( "The jvm was unset" . to_string ( ) ) ?
14731473 . lock ( )
1474- . unwrap ( )
1474+ . map_err ( |_| "Could not lock mutex" . to_string ( ) ) ?
14751475 . class_loader ( )
14761476 . as_ref ( )
14771477 . unwrap ( )
@@ -1491,7 +1491,7 @@ impl<'a> JavaEnvWrapper<'a> {
14911491 . as_ref ( )
14921492 . ok_or ( "The jvm was unset" . to_string ( ) ) ?
14931493 . lock ( )
1494- . unwrap ( )
1494+ . map_err ( |_| "Could not lock mutex" . to_string ( ) ) ?
14951495 . set_class_loader ( loader) ;
14961496
14971497 Ok ( ( ) )
Original file line number Diff line number Diff line change @@ -86,12 +86,12 @@ export interface JVMOptions extends JavaOptions {
8686 * in an altered classpath in your java application/library if your
8787 * application is using a custom classpath (e.g. Spring Boot).
8888 *
89- * Also, it is not possible to restart the jvm after is has been started
89+ * Also, it is not possible to restart the jvm after it has been started
9090 * once, in order to alter the startup classpath. This is due to some
9191 * limitations with the destructor feature of the node.js native api,
9292 * which may not call the destructor in time and having two jvm instances
9393 * in the same application is not allowed by java. Additionally, destroying
94- * the jvm instance may cause *undefined behaviour *, which may or may not
94+ * the jvm instance may cause *undefined behavior *, which may or may not
9595 * cause the application to crash. Let's not do that.
9696 *
9797 * @param options the options to use when creating the jvm
@@ -104,7 +104,7 @@ export function ensureJvm(options?: JVMOptions): boolean {
104104 options ?. version ,
105105 options ?. opts ,
106106 options ,
107- getJavaLibPath ( ) ,
107+ getJavaLibPath ( options ?. isPackagedElectron ?? false ) ,
108108 getNativeLibPath ( options ?. isPackagedElectron ?? false )
109109 ) ;
110110
Original file line number Diff line number Diff line change @@ -91,11 +91,15 @@ export function getNativeLibPath(isPackagedElectron: boolean): string {
9191 }
9292}
9393
94- export function getJavaLibPath ( ) : string {
94+ export function getJavaLibPath ( isPackagedElectron : boolean ) : string {
9595 const lib = path . join ( __dirname , 'JavaBridge.jar' ) ;
9696
9797 if ( fs . existsSync ( lib ) && fs . statSync ( lib ) . isFile ( ) ) {
98- return lib ;
98+ if ( isPackagedElectron ) {
99+ return lib . replace ( APP_ASAR_REGEX , APP_ASAR_UNPACKED ) ;
100+ } else {
101+ return lib ;
102+ }
99103 } else {
100104 throw new Error ( 'JavaBridge.jar not found' ) ;
101105 }
You can’t perform that action at this time.
0 commit comments