scalameta / sbt-native-image

Plugin to generate native-image binaries with sbt
252 stars 22 forks source link

java.lang.NoClassDefFoundError: Ljava/nio/ByteBuffer - when running a JavaFX app #41

Open makingthematrix opened 2 years ago

makingthematrix commented 2 years ago

Describe the bug

If I build a native image with JavaFX and try to run it, an error crashes the app at initialization:

Exception in thread "main" java.lang.RuntimeException: java.lang.NoClassDefFoundError: Ljava/nio/ByteBuffer;
  | => nat com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:290)
        at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:288)
...

To Reproduce Steps to reproduce the behavior:

I prepared a minimal example and put the steps to reproduce the error in the description: https://github.com/makingthematrix/javafx_sbt_minimal

tonivade commented 2 years ago

try to add this option to your nativeImage configuration:

    s"-H:JNIConfigurationFiles=${(Compile / resourceDirectory).value / "jni-config.json"}",

Had a similar problem and it was fixed with this option: