I'm compiling to native a javafx app using gluonfx plugin. To perform some network functions I needed to add some pcap dependencies, I tested in debug mode and everything goes fine. But after compile to native I have the following error when I try to use the implemented function:
Exception in thread "JavaFX Application Thread" java.util.ServiceConfigurationError: pcap.spi.Service: Provider pcap.jdk7.internal.DefaultService could not be instantiated
at java.util.ServiceLoader.fail(ServiceLoader.java:582)
at java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:804)
at java.util.ServiceLoader$ProviderImpl.get(ServiceLoader.java:722)
at java.util.ServiceLoader$3.next(ServiceLoader.java:1395)
at pcap.spi.Service$Creator.<clinit>(Service.java:343)
at [project path].VdsConfiguratorService.getNetworkInterfaces(VdsConfiguratorService.java:27)
at [project path].vdsswitchconfig.VdsSwitchConfigurator.<init>(VdsSwitchConfigurator.java:20)
at [project path].GuiExtraStarter.show(GuiExtraStarter.java:84)
at [project path].FxMainMenu.lambda$updateContent$7(FxMainMenu.java:80)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.control.MenuItem.fire(MenuItem.java:459)
at com.sun.javafx.scene.control.ContextMenuContent$MenuItemContainer.doSelect(ContextMenuContent.java:1385)
at com.sun.javafx.scene.control.ContextMenuContent$MenuItemContainer.lambda$createChildren$12(ContextMenuContent.java:1338)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:247)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3881)
at javafx.scene.Scene.processMouseEvent(Scene.java:1874)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2607)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:411)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:301)
at java.security.AccessController.doPrivileged(AccessController.java:107)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:450)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:424)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:449)
at com.sun.glass.ui.View.handleMouseEvent(View.java:551)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.oracle.svm.jni.JNIJavaCallWrappers.jniInvoke_VA_LIST_View_notifyMouse_4f1a8388c3763e6ef91b5795c9a3bb669af40a28(JNIJavaCallWrappers.java:0)
at com.sun.glass.ui.win.WinApplication._runLoop(WinApplication.java)
at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
at java.lang.Thread.run(Thread.java:829)
at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:597)
at com.oracle.svm.core.windows.WindowsJavaThreads.osThreadStartRoutine(WindowsJavaThreads.java:140)
Caused by: java.lang.UnsatisfiedLinkError: Native library (com/sun/jna/win32-x86-64/jnidispatch.dll) not found in resource path ()
at com.sun.jna.Native.loadNativeDispatchLibraryFromClasspath(Native.java:1033)
at com.sun.jna.Native.loadNativeDispatchLibrary(Native.java:989)
at com.sun.jna.Native.<clinit>(Native.java:195)
at com.sun.jna.Structure.setAlignType(Structure.java:291)
at com.sun.jna.Structure.<init>(Structure.java:208)
at com.sun.jna.Structure.<init>(Structure.java:204)
at com.sun.jna.Structure.<init>(Structure.java:191)
at com.sun.jna.Structure.<init>(Structure.java:183)
at pcap.jdk7.internal.NativeMappings$ErrorBuffer.<init>(NativeMappings.java:734)
at pcap.jdk7.internal.NativeMappings$ErrorBuffer.<init>(NativeMappings.java:731)
at pcap.jdk7.internal.DefaultService.<init>(DefaultService.java:33)
at java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:780)
... 51 more
Code that fails:
var service = Service.Creator.create("PcapService"); **//This line throws the exception**
for (Interface device : service.interfaces()) {
...
}
Dependencies added:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.ardikars.pcap</groupId>
<artifactId>pcap</artifactId>
<version>1.4.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.ardikars.pcap</groupId>
<artifactId>pcap-jdk7</artifactId>
</dependency>
</dependencies>
Thanks in advance!
Solved after comment of @JosePereda.
By running mvn gluonfx:runagent
the necessary configuration was automatically added to resources/META-INF.nativeimages/ files.
After that compiled again with mvn gluonfx:build
and the app run successfully and I was able to query the function.
@JosePereda Thanks one more time crack!