Unexpected crash on java.import() using more modules
I am requiring two modules (module x and module y) from the main module. Both the required modules call var java = require('java'). In the main module I first require module x and everything works well. When I require module y the app crashes without printing exeptions in the console. Anyway I figured out that the crash happens while calling java.import('class name'), and more precisely in the nodeJavaBridge.js file by the findClassSync(name) Line:227 method. I think that there is a JVM problem: in my opinion the JVM is created by module x and can't be created again by module y, so findClassSync(name) can't work.
How can I use both modules without crashing?
I'm guessing this is two different versions of node-java being loaded. You could probably force the version using node shrinkwrap like in this post https://stackoverflow.com/a/37400568
I'm not sure of the best way to handle this in the long term. Maybe setting a global variable in node-java which holds a reference to the loaded native library?
Thank you @joeferner but this issue happens also with the same versions. I am trying to solve it. I will update my code if I successed. In the meanwhile I will wait for other answers.
hi, have you solved this problem? I am facing the same problem when use node-java in Electron
Hi @HarveyLee1228 , yes, I remember I solved the problem, but it's been a long time ago, and honestly, I don't remember my solution. I only remember that, referring to that version of this package, the java files were loaded when the require() function was called, and so I added a function to explicitly load the java classes when they were ready. But my memories could be completely wrong. Unfortunately I can't help you on this topic. I hope you will find a better solution that can be included in this package.