Reputation: 87
I am packaging a jar file with
gradlew desktop:dist
when running it with java 1.8 (openjdk)
java -jar desktop-1-0.jar
a ClassNotFoundException for the FreeTypeFontGenerator class is thrown. The whole Stacktrace is the following
java -jar desktop-1.0.jar Picked up _JAVA_OPTIONS: -Xmx512M Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.NoClassDefFoundError: com/badlogic/gdx/graphics/g2d/freetype/FreeTypeFontGenerator at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:135) Caused by: java.lang.NoClassDefFoundError: com/badlogic/gdx/graphics/g2d/freetype/FreeTypeFontGenerator at com.mygdx.tools.FontLoader.loadFont(FontLoader.java:13) at com.mygdx.stages.hud.ClientHud.(ClientHud.java:42) at com.mygdx.stages.hud.StartmenuHud.joinButtonClicked(StartmenuHud.java:67) at com.mygdx.stages.hud.StartmenuHud.access$100(StartmenuHud.java:16) at com.mygdx.stages.hud.StartmenuHud$2.touchDown(StartmenuHud.java:47) at com.badlogic.gdx.scenes.scene2d.InputListener.handle(InputListener.java:57) at com.badlogic.gdx.scenes.scene2d.Actor.notify(Actor.java:188) at com.badlogic.gdx.scenes.scene2d.Actor.fire(Actor.java:158) at com.badlogic.gdx.scenes.scene2d.Stage.touchDown(Stage.java:281) at com.badlogic.gdx.backends.lwjgl.LwjglInput.processEvents(LwjglInput.java:357) at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:221) at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:128) Caused by: java.lang.ClassNotFoundException: com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator 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) ... 12 more
I already included the necessary dependencies in the build.gradle file within the root directory of my project for FreeTypeFont as described in the libgdx wiki.
I also refreshed the project dependencies (right-click project -> Gradle -> Refresh Gradle Dependencies) and rebuild the project.
Upvotes: 0
Views: 435
Reputation: 87
The solution for me was to add
implementation "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
under the desktop section of my build.gradle file. I tried this out since the import for the controler module looked a bit alike.
I have no idea why this is not documented, but after a refresh of all gradle dependencies (right-click the project -> Gradle -> Refresh Gradle Dependencies) and a rebuild of the project i was able to run the packaged jar without any problems.
Upvotes: 1