Skip to content

Electron/Java compatiblity? #379

Open

Description

@vrmerlin

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

  1. dasarindam commented on Feb 9, 2017

    @dasarindam

    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 ?

  2. dasarindam commented on Feb 9, 2017

    @dasarindam

    I build java.
    I build electron too.
    Now it goes back to 1st erreor.
    ELECTRON_ASAR.js:173:20 ....

  3. vrmerlin commented on Feb 9, 2017

    @vrmerlin
    Author

    Here are the two steps I did to rebuild Electron:

    npm install --save-dev electron-rebuild
    .\node_modules\.bin\electron-rebuild.cmd
    
  4. vrmerlin commented on Feb 9, 2017

    @vrmerlin
    Author

    Also, I tried running the command npm rebuild --runtime=electron --target=1.6.0 --msvs_version=2015 --arch=x64 and got this compile error in the Java code:

    ..\src\utils.cpp(494): error C3083: 'NewStringType': the symbol to the left of a '::' must be a type [C:\devel\narac-sample-ui\node_modules\java\build\nodejavabridge
    _bindings.vcxproj]
    ..\src\utils.cpp(494): error C2039: 'kNormal': is not a member of 'v8' [C:\devel\narac-sample-ui\node_modules\java\build\nodejavabridge_bindings.vcxproj]
      C:\Users\fisher23\.node-gyp\iojs-1.6.0\deps\v8\include\v8.h(65): note: see declaration of 'v8'
    ..\src\utils.cpp(494): error C2065: 'kNormal': undeclared identifier [C:\devel\narac-sample-ui\node_modules\java\build\nodejavabridge_bindings.vcxproj]
    ..\src\utils.cpp(494): error C2228: left of '.ToLocalChecked' must have class/struct/union [C:\devel\narac-sample-ui\node_modules\java\build\nodejavabridge_bindings.
    vcxproj]
    

    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.

  5. dasarindam commented on Feb 10, 2017

    @dasarindam

    Still i could not make it work...
    Can you let me know the steps that you have followed.
    TIA.

  6. vrmerlin commented on Feb 10, 2017

    @vrmerlin
    Author

    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)

  7. dasarindam commented on Feb 10, 2017

    @dasarindam

    Continued to have same problem... Below are the command that I have ran after extracting the Electron-quick-start....

    > npm install --arch=x64 --msvs_version=2015
    > npm install electron-rebuild --save-dev
    > npm install java
    > node_modules\.bin\electron-rebuild
    > node node_modules\java\postInstall.js
    
  8. yahyaKacem commented on Apr 24, 2017

    @yahyaKacem

    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:

    electron-forge init new-test-app
    cd new-test-app
    yarn start // or npm start
    

    works, then followed the provided steps again:

    npm install --arch=x64 --msvs_version=2015
    npm install electron-rebuild --save-dev
    npm install java
    node_modules\.bin\electron-rebuild
    node node_modules\java\postInstall.js
    yarn start // or npm start
    

    works, then add this line import { java } from 'java'; to the entry file src/index.js,
    and after yarn start again get the same error:

    yarn start v0.22.0
    $ electron-forge start
    √ Checking your system
    √ Locating Application
    √ Preparing native dependencies: 1 / 1
    √ Launching Application
    
    App threw an error during load
    Error: The specified module could not be found.
    \\?\C:\Path\To\Project\new-test-app\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 Object.<anonymous> (C:\Path\To\Project\new-test-app\node_modules\java\lib\nodeJavaBridge.js:21:16)
        at Object.<anonymous> (C:\Path\To\Project\new-test-app\node_modules\java\lib\nodeJavaBridge.js:316:3)
    

    Also when running yarn make or yarn package the 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.node it does exist.

  9. dasarindam commented on May 30, 2017

    @dasarindam

    I tried building a new apps today. Its not building again.

    node-java

    1. -- was the build that i did 1st time and it still working
    2. -- is the build I tried today. (See the version diff)
    3. -- the version installed in my machine.

    I also tried building with the Old config as (1) - But no luck though. Gettting error something like this.

    C:\MyRD\Electron\electron-quick-start-master\DBClone\node_modules\java\lib\nodeJavaBridge.js:227 Uncaught
    Uncaught Error: Could not create class com.db.util.JavaTestPack
    java.lang.NoClassDefFoundError: com/db/util/JavaTestPack

    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...

  10. gpinkham commented on Apr 30, 2019

    @gpinkham

    Not sure if this is a valid solution but what I did after installing was running electron-rebuild I believe this does not run any postInstall steps so the build/jvm_dll_path.json file 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..).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions