-1

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 !

pacataque
  • 86
  • 11
  • Please include stacktrace... – blurfus Jun 14 '21 at 15:36
  • Maybe it is possible (with some overhead!) to get more info with: `-Xlog:class+load=info` (or even debug), and maybe `-Xlog:exceptions=info`. See for more options (like unloading etc.) also: https://bugs.openjdk.java.net/browse/JDK-8232773 and the (improved documentation on newer Java versions, the options date back to Java 9): https://docs.oracle.com/en/java/javase/15/docs/specs/man/java.html#enable-logging-with-the-jvm-unified-logging-framework – JohannesB Jun 23 '21 at 09:34

1 Answers1

0

A NoClassDefFoundError should mean, as commented here, the your myPackage.jfx.gui.misc.ClipboardHelper module is not placed on the module-path nor the class-path.

Make sure the module is actually resolved as a module via either a requires directive in your module descriptor, or the --add-modules argument if your code is not modular

double check your runtime arguments:

--module-path C:\Users<user>\Downloads\javafx-sdk-11\lib --add-modules=javafx.controls

You can complete them to reference your own module.

As noted in this question: "--add-modules necessary for modules which are on the module path".

VonC
  • 1,129,465
  • 480
  • 4,036
  • 4,755
  • Check also the version compatibility, as in https://stackoverflow.com/a/59804078/6309 – VonC Jun 17 '21 at 07:59
  • Thanks for your answer Why should I need to add my own modules if they are in my dependencies ? Then if they are not added, they should not be usable at all, right ? Here it's working in most of the cases but sometimes (maybe after that the app was launch since a moment, I don't know) I can see these exceptions for some users in the logs... I suppose that the NoClassDefFound is not the issue, what is strange here is the ClassNotFound. And the NoClassDefFound is a consequence of it – pacataque Jun 17 '21 at 14:01
  • @pacataque So that means: the class exists, is present in your classpath, but I suspect fails to instantiate because of static variables or static blocs initialization exception. – VonC Jun 17 '21 at 15:15
  • It could be but I have this issue for a private class that contains nor static variable nor static bloc – pacataque Jun 18 '21 at 06:45
  • Can you, for testing, remove that class, making sure your program does not use it, again temporarily, just for testing. And see if the error persists for another class or not. – VonC Jun 18 '21 at 07:06
  • I have this issue for many classes Should I remove all ? The problem is that I don't know how to reproduce it, I think that the user' session is open since a while (sleep mode can affect javafx behaviour ?) – pacataque Jun 18 '21 at 08:33