I have an issue with a javafx 11 application. Every days I can see in log file some NoClassDefFoundError due to ClassNotFoundExceptions. This Exception can happen on different classes. These classes could be internal classes or can come from an external lib that I'm using. These classes are present in my exe file (I can see it if I open the archive) and in most of the case this class is usable but, I don't know why, sometimes this exception is thrown.
This is how I package my app :
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>1.3.56</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>1.3.56</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>1.3.56</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>1.3.56</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.56</version>
<configuration>
<mainClass>mypackage.MyMain</mainClass>
<arguments>
<argument>-db</argument>
<argument>dbURL</argument>
</arguments>
<systemProperties>
<systemProperty>
<key>java.security.manager</key>
</systemProperty>
<systemProperty>
<key>java.security.policy</key>
<value>$MODULE_DIR$/src/main/resources/client.policy</value>
</systemProperty>
<systemProperty>
<key>prism.order</key>
<value>j2d</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
<plugin>
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
<version>1.7.25</version>
<executions>
<execution>
<id>l4j-clui</id>
<phase>package</phase>
<goals>
<goal>launch4j</goal>
</goals>
<configuration>
<headerType>gui</headerType>
<jar>${basedir}/target/${project.artifactId}-${project.version}-jar-with-dependencies.jar</jar>
<outfile>${basedir}/target/App.exe</outfile>
<downloadUrl>http://java.com/download</downloadUrl>
<classPath>
<mainClass>mypackage.MyMain</mainClass>
</classPath>
<icon>${basedir}/src/main/resources/images/myIcon.ico</icon>
<jre>
<path>${jdk.path}</path>
<bundledJre64Bit>true</bundledJre64Bit>
<bundledJreAsFallback>true</bundledJreAsFallback>
<minVersion>11</minVersion>
<jdkPreference>preferJre</jdkPreference>
<runtimeBits>32</runtimeBits>
<opts>
<opt>-Xmx768M -Djava.security.policy==#/client.policy</opt>
<opt>-Djava.rmi.server.useCodebaseOnly=false</opt>
<opt>--module-path="myPath\Amazon Corretto\jdk11.0.5_10\javafx-sdk-11.0.2\lib"</opt>
<opt>--add-modules=javafx.base,javafx.controls,javafx.graphics</opt>
<opt>Lot of opt like that</opt>
</opts>
</jre>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
This is the exception :
ERROR myPackage.jfx.gui.MyClass - java.lang.NoClassDefFoundError: myPackage/jfx/gui/misc/ClipboardHelper
at myPackage.jfx.gui.MyClass.getContent(MyClass.java:132)
at myPackage.app.client.ui.controls.EnhancedMyClass.getContent(EnhancedMyClass.java:149)
at myPackage.jfx.gui.MyClassSkin.setupDragDropContent(MyClassSkin.java:433)
at myPackage.jfx.gui.MyClassSkin$4.handle(MyClassSkin.java:139)
at myPackage.jfx.gui.MyClassSkin$4.handle(MyClassSkin.java:131)
at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
at javafx.graphics/javafx.scene.Scene$DnDGesture.fireEvent(Scene.java:3027)
at javafx.graphics/javafx.scene.Scene$DnDGesture.process(Scene.java:3106)
at javafx.graphics/javafx.scene.Scene$DnDGesture.access$8300(Scene.java:3003)
at javafx.graphics/javafx.scene.Scene$MouseHandler.process(Scene.java:3867)
at javafx.graphics/javafx.scene.Scene$MouseHandler.access$1200(Scene.java:3579)
at javafx.graphics/javafx.scene.Scene.processMouseEvent(Scene.java:1849)
at javafx.graphics/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2588)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:397)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:434)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:390)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:433)
at javafx.graphics/com.sun.glass.ui.View.handleMouseEvent(View.java:556)
at javafx.graphics/com.sun.glass.ui.View.notifyMouse(View.java:942)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.ClassNotFoundException: myPackage.jfx.gui.misc.ClipboardHelper
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 51 more
Is something wrong in it ? How can I have a ClassNotFoundException if my classes are included in my .exe file.
Sometimes this issue is not visible for the user (task in background) depending on the class. But when the exception appears, the user can restart the app and all is working perfectly fine. Could the time or sleeping mode have an impact on javafx app ?
Thanks a lot !