Repository navigation
Electron/Java compatiblity? #379
Description
I'm trying to create an Electron application that uses Java to access some legacy code. I could get it to work with NW.js, but I can't seem to get it to work with Electron on Windows. Here's what I've done:
-
Installed the windows-build-tools npmjs module (that in turns installs Python and the MS VS command line build).
-
Cloned the electron-quick-start and verified that it built and ran correctly on my system.
Installed the Java module (version 0.80) into package.json. After downloading, it did a successful build process. -
Removed the node_modules directory and did an npm install again. Again, I can see the Java support files (.cpp) compiling as expected, with no errors.
-
Ran the electron-quick-start again, and it came up with no problems.
-
Added the line const java = require('java') to the main.js of electron-quick-start
-
When I run the sample, I see the following error:
App threw an error during load
Error: A dynamic link library (DLL) initialization routine failed.
\\?\C:\devel\electron-quick-start\node_modules\java\build\Release\nodejavabridge_bindings.node
at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:173:20)
at Object.Module._extensions..node (module.js:598:18)
at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:173:20)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at C:\devel\electron-quick-start\node_modules\java\lib\nodeJavaBridge.js:21:16
at Object.<anonymous> (C:\devel\electron-quick-start\node_modules\java\lib\nodeJavaBridge.js:316:2)
- At this point, I tried installing and running electron-rebuild. When I re-ran the sample, I then got this error:
Error: Cannot find module '../build/jvm_dll_path.json'
at Module._resolveFilename (module.js:470:15)
at Function.Module._resolveFilename (C:\devel\electron-quick-start\node_modules\electron\dist\resources\electron.asar\common\reset-search-paths.js:35:12)
at Function.Module._load (module.js:418:25)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at C:\devel\electron-quick-start\node_modules\java\lib\nodeJavaBridge.js:3:21
at Object.<anonymous> (C:\devel\electron-quick-start\node_modules\java\lib\nodeJavaBridge.js:316:2)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)- So, I thought maybe at this point, I need to rebuild the Java, so I did the following:
node-gyp rebuild
npm run postinstall
cd ..\..
Unfortunately, when I ran the sample, I simply got the first error message again.
Any ideas out there? I feel like I'm really close, but can't quite get the build steps correct.
John
Activity
dasarindam commentedon Feb 9, 2017
Me too trying the same. Tried all the thing ...
I didnt get the error of missing JVM file.
how did you tried to rebuilt the electron ? What command did you used ?
dasarindam commentedon Feb 9, 2017
I build java.
I build electron too.
Now it goes back to 1st erreor.
ELECTRON_ASAR.js:173:20 ....
vrmerlin commentedon Feb 9, 2017
Here are the two steps I did to rebuild Electron:
vrmerlin commentedon Feb 9, 2017
Also, I tried running the command
npm rebuild --runtime=electron --target=1.6.0 --msvs_version=2015 --arch=x64and got this compile error in the Java code:I should comment that I can't get this to work on Linux now, either. At one point it worked, but I think it was the luck of versioning (Node/Electron/Java/whatever) that it just happened to work. I'm getting the same error behaviors on that OS.
dasarindam commentedon Feb 10, 2017
Still i could not make it work...
Can you let me know the steps that you have followed.
TIA.
vrmerlin commentedon Feb 10, 2017
I finally got it to work. Here are the commands:
npm install --arch=x64 --msvs_version=2015 node_modules\.bin\electron-rebuild node node_modules\java\postInstall.js@joeferner -- it looks like this is a bug in the java module. @MarshallOfSound found and fixed the problem here:
electron/electron#8638 (comment)
dasarindam commentedon Feb 10, 2017
Continued to have same problem... Below are the command that I have ran after extracting the Electron-quick-start....
yahyaKacem commentedon Apr 24, 2017
still having the same error here with windows 10, tried electron-quick-start as mentioned above with the steps provided by @dasarindam and others nothing changed.
also tried generating a new app with electron-forge like this:
works, then followed the provided steps again:
works, then add this line
import { java } from 'java';to the entry filesrc/index.js,and after
yarn startagain get the same error:Also when running
yarn makeoryarn packagethe error appear when launching the app's installer and the make/packaging finish successfully.I checked the path to that file
C:\Path\To\Project\new-test-app\node_modules\java\build\Release\nodejavabridge_bindings.nodeit does exist.dasarindam commentedon May 30, 2017
I tried building a new apps today. Its not building again.
I also tried building with the Old config as (1) - But no luck though. Gettting error something like this.
The 227 of this js file is commented and TODO--- Not sure what might be the issue.
var clazz = java.findClassSync(name); // TODO: change to Class.forName when classloader issue is resolved.Hope to get a quick resolve...
gpinkham commentedon Apr 30, 2019
Not sure if this is a valid solution but what I did after installing was running
electron-rebuildI believe this does not run any postInstall steps so thebuild/jvm_dll_path.jsonfile is missing.. I manually created it and all was well.but this brings up an interesting issue I think Electron apps will have.. This is a build time location for Java.. not the location of Java on the client computer. It would mean the Electron app would only work if the same exact java version/build was installed (so the locations match). @joeferner am I understanding this correctly? I had thought about patching it to find Java at runtime.. but then the binding may not match (jdk 8 vs 9 etc..).