Using JWebBrowser from installed app
Web Browser, Flash Player, HTML editor, Media player for Swing and SWT
Brought to you by:
chrriis
Hi,
I have an applicatin which uses JWebBrowser and it works correctly started from IntelliJ. I installed that application by installer created by jpackage tool and starting the installed app I got the following:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Failed to spawn the peer VM!
at chrriis.dj.nativeswing.swtimpl.core.SWTNativeInterface$OutProcess.createProcess(SWTNativeInterface.java:982)
at chrriis.dj.nativeswing.swtimpl.core.SWTNativeInterface$OutProcess.createOutProcessMessagingInterface(SWTNativeInterface.java:1025)
at chrriis.dj.nativeswing.swtimpl.core.SWTNativeInterface$OutProcess.createOutProcessCommunicationChannel(SWTNativeInterface.java:811)
at chrriis.dj.nativeswing.swtimpl.core.SWTNativeInterface.open_(SWTNativeInterface.java:342)
at chrriis.dj.nativeswing.swtimpl.NativeInterface.open(NativeInterface.java:100)
at org.bitbucket.lorandkutvolgyi.ui.BrowserPanel.<init>(BrowserPanel.java:37)
at org.bitbucket.lorandkutvolgyi.Main.createDependencies(Main.java:143)
at java.desktop/java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Unknown Source)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.desktop/java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: java.io.IOException: Cannot run program "/opt/<myapp>/lib/runtime/bin/java": error=2, Nincs ilyen fájl vagy könyvtár
at chrriis.dj.nativeswing.swtimpl.core.DefaultPeerVMProcessFactory.createProcess(DefaultPeerVMProcessFactory.java:117)
at chrriis.dj.nativeswing.swtimpl.core.SWTNativeInterface$OutProcess.createProcess(SWTNativeInterface.java:980)
... 19 more
Caused by: java.io.IOException: Cannot run program "/opt/<myapp>/lib/runtime/bin/java": error=2, Nincs ilyen fájl vagy könyvtár
at java.base/java.lang.ProcessBuilder.start(Unknown Source)
at java.base/java.lang.ProcessBuilder.start(Unknown Source)
at chrriis.dj.nativeswing.swtimpl.core.DefaultPeerVMProcessFactory.createProcess(DefaultPeerVMProcessFactory.java:115)
... 20 more
Caused by: java.io.IOException: error=2, Nincs ilyen fájl vagy könyvtár
at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)
at java.base/java.lang.ProcessImpl.<init>(Unknown Source)
at java.base/java.lang.ProcessImpl.start(Unknown Source)
Java runtime created by the installer is in /opt/<myapp>/lib/runtime/. But bin/java does not exist under it and that causes the problem. Could you help me how can I use JWebBrowser from the installed app?
Hi,
I am not too familiar with the jpackage tool. But one thing is sure: the native side that is manipulated by the Swing side needs to be in its own VM, so a separate java process is started. I don't know how a new VM can be spawned from an application packaged this way.
If you do have a way to start a VM, for example by shipping the java exe, etc., then I suppose you could set a different process factory if the default one is not suitable:
NativeInterface.getConfiguration().setPeerVMProcessFactory(MyPeerVMProcessFactoryImplementation)
Note that such factory could be adapted from the default implementation:
https://github.com/Chrriis/DJ-Native-Swing/blob/master/DJNativeSwing-SWTCore/src/chrriis/dj/nativeswing/swtimpl/core/DefaultPeerVMProcessFactory.java
I hope you will find a way around this! If you do, please share your findings!
Cheers,
-Christopher
Hi!
I found out the solution. If not letting jpackage create runtime but creating it by jlink and pass it to jpackage everything works perfectly. In this case the runtime can be used from outside not only by the packaged app. There is bin directory and java under it, etc.
Cheers,
Lóránd