node-java icon indicating copy to clipboard operation
node-java copied to clipboard

Packagged the jdk in app node linux

Open dbouchierarcad opened this issue 5 years ago • 7 comments

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.

dbouchierarcad avatar Nov 16 '20 08:11 dbouchierarcad

I want this too

Heath123 avatar Dec 28 '20 21:12 Heath123

But this project seems mostly dead

Heath123 avatar Dec 28 '20 21:12 Heath123

In the end I just used WebSockets to communicate with the Java process because they're less buggy

Heath123 avatar Dec 30 '20 19:12 Heath123

@dbouchierarcad did you ever find a solution to this?

ChrisTomAlx avatar Mar 03 '21 07:03 ChrisTomAlx

@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 avatar Mar 03 '21 08:03 dbouchierarcad

@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/build folder in your app then use node-gyp to rebuild the node_modules/java/binding.gyp file, then run node node_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 avatar Mar 04 '21 07:03 ChrisTomAlx

@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?

hollomyfoolish avatar Jul 08 '21 06:07 hollomyfoolish