Packagged the jdk in app node linux
Hello,
I would like to embed my jdk in my node application. On the windows platform, I manage to do it by modifying the path in the file under java / build / jvm_dll_path.json. Now in linux it doesn't work. It always gives me the error "Error: libjvm.so: cannot open shared object file: No such file or directory" because the path is that of the machine on which the projet was compiled, i don't want recompile.
Can you modify the path of JAVA HOME without recompiling under linux? Sort of having a dynamic jdk path embedded in the node application.
I want this too
But this project seems mostly dead
In the end I just used WebSockets to communicate with the Java process because they're less buggy
@dbouchierarcad did you ever find a solution to this?
@ChrisTomAlx No at now, on a linux environment I copy the embedded jdk in my application by creating the path saved in the jvm_dll_path.json file.
@dbouchierarcad Thanks a ton, this saved me many hours of grueling research. For anyone else stumbling upon this, Basically when you do npm install, the java library takes the JAVA_HOME env variable of the current machine, then using this gets the path to the server folder where libjvm exists. This value is then stored in java/build/jvm_dll_path.json.
The problem occurs when you move this build to a different machine (In devops configurations), the JAVA_HOME paths will be different hence it throws errors. Simply changing this string in the jvm_dll_path.json file will work only if both machines were windows machines. On linux like suggested above you have to either copy or create a symbolic links of the JRE folder from your original JAVA path to the one specified in the JSON file.
Some other workarounds for this could be :-
- Make sure the environments in both your build machine and deploy machine match exactly (JAVA_HOME Paths, Operating System and NodeJS versions must match)
- Use Docker, with JAVA_HOME correctly specified
- In your new machine where you are deploying the app, delete the
node_modules/java/buildfolder in your app then use node-gyp to rebuild thenode_modules/java/binding.gypfile, then run nodenode_modules/java/postinstall.js, this should ideally work even when you move between different operating systems. You also probably need sudo permissions to do these.
Hope this helps someone :)
@ChrisTomAlx @dbouchierarcad Thanks so much for you sharing, I have try this all day and fail again and again untill I find this post tell me all my time are usless..., I guess the autho will not solve this issue, right?