node-java java.import not working with a packaged electron app
See original GitHub issueCross reporting the issue reported in node-java
https://github.com/joeferner/node-java/issues/352
With a package app using an asar archive, java.import
does not work.
The following line of code will throw an error:
var DateTime = java.import('org.joda.time.DateTime');
Error: Could not create class org.joda.time.DateTime
java.lang.NoClassDefFoundError: org/joda/time/DateTime
Caused by: java.lang.ClassNotFoundException: org.joda.time.DateTime
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at Error (native)
at Java.java.import (...)
Only the packaged version of the app fails. Launching the unpackaged electron app will work fine.
The app was packaged with the following command:
electron-packager ./app --out=dist --asar.unpack='**/node_modules/java/**/*'
I guess the function java.import
needs to be adapted in order to work with packaged electron apps.
Let me know if I can provide more information.
regards
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Cannot install NPM package "java" alongside Electron
Before installing Java, we need to install Windows build tools using the following command: npm install --global --production windows-build- ...
Read more >java-electron - npm
Start using java-electron in your project by running `npm i ... status 1" Try running node findJavaHome.js in the node-java directory to see ......
Read more >Can Aspose.Cells for Javascript via Java run in Electron?
I realize this is an issue with the node-java package and not aspose, but figured I'd ask. Any help would be appreciated. Thanks!...
Read more >java-bridge - NPM Package Overview - Socket - Socket.dev
node-java ... In contrast to other node.js <-> java interfaces, the binary is not hard ... When using this package in a packaged...
Read more >File Upload in ElectronJS - GeeksforGeeks
For Electron to work, node and npm need to be pre-installed in the system. ... To import and use the dialog Module in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@antoinepairet I think the issue is that the internal classpath paths in
node-java
need to be using theasar.unpacked
directory instead of theapp.asar
one. https://github.com/joeferner/node-java/blob/126bfa821cefcb8af21e323990d9985936938a97/lib/nodeJavaBridge.js#L23-L31I got it working with the following patch to your repo:
@antoinepairet I know this is a really old issue but curious. how did that code work for you? building the electron app with webpack ends up including both requires (it doesn’t run the if statement). Did you use some other packer? thanks!!