0

I am following this tutorial: docs.oracle.com

I have successfully built it using

javac --module-path /usr/lib/jvm/java-13-openjdk/lib --add-modules javafx.controls -d . -Xmaxerrs 1 HelloWorld.java

and archived it using

jar cfm j.jar manifest helloworld/*.class

then ran it using

java -jar j.jar

and then I got the error:

Error: Could not find or load main class helloworld.HelloWorld Caused by: java.lang.NoClassDefFoundError: javafx/application/Application

To be clear, there are many questions about JavaFX here, however they all seem to deal with pre-Java 8, where you need to add jfxrt.jar to the classpath. But since JavaFX is now a separate module from Java JDK, these answers do not seem to apply anymore.

(Yes, I have installed java-openjfx package on Linux.)

I'm not sure if what I'm missing is JavaFX specific or something more general to 'linking' jar files/modules in Java.


Edit:

After seeing this question, I copied my JavaFX lib folder (minus jrt-fs.jar), included javafx.graphics in my added modules, and added the modules when running (as Nand commented below), and now this is the error I'm getting. Still not sure what's going on.

Exception in Application start method
java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:567)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:567)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
    at java.base/java.lang.Thread.run(Thread.java:830)
Caused by: java.lang.ExceptionInInitializerError
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.createTKStage(QuantumToolkit.java:600)
    at javafx.graphics/javafx.stage.Stage.doVisibleChanging(Stage.java:1154)
    at javafx.graphics/javafx.stage.Stage$1.doVisibleChanging(Stage.java:182)
    at javafx.graphics/com.sun.javafx.stage.StageHelper.visibleChangingImpl(StageHelper.java:57)
    at javafx.graphics/com.sun.javafx.stage.WindowHelper.visibleChanging(WindowHelper.java:73)
    at javafx.graphics/javafx.stage.Window$12.invalidated(Window.java:1064)
    at javafx.base/javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:110)
    at javafx.base/javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:145)
    at javafx.graphics/javafx.stage.Window.setShowing(Window.java:1174)
    at javafx.graphics/javafx.stage.Window.show(Window.java:1189)
    at javafx.graphics/javafx.stage.Stage.show(Stage.java:273)
    at helloworld.HelloWorld.start(HelloWorld.java:29)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
    ... 1 more
Caused by: java.util.MissingResourceException: Can't find bundle for base name com.sun.javafx.tk.quantum.QuantumMessagesBundle, locale en_US
    at java.base/java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:2055)
    at java.base/java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1689)
    at java.base/java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1582)
    at java.base/java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1556)
    at java.base/java.util.ResourceBundle.getBundle(ResourceBundle.java:932)
    at javafx.graphics/com.sun.javafx.tk.quantum.WindowStage.<clinit>(WindowStage.java:101)
    ... 21 more
Exception running application helloworld.HelloWorld
C. Dunn
  • 101
  • 1
  • 6
  • Provide the module path and add modules in the `java` command as well. – Nand Feb 01 '20 at 14:00
  • Thanks for the response, however I have tried the following to no avail: `java --module-path /usr/lib/jvm/java-13-openjdk/lib --add-modules javafx.controls -jar j.jar` – C. Dunn Feb 01 '20 at 15:39
  • 1
    Check this out: https://openjfx.io/openjfx-docs/#install-javafx, and if that doesn't work, check out the "Runtime images" part – Nand Feb 01 '20 at 15:45
  • I think this is the right track. While I don't have it solved yet, it appears my main issue may be related to [this](https://stackoverflow.com/questions/42986287/runtimeexception-package-jdk-internal-jimage-decompressor-in-module-jrt-fs-and) – C. Dunn Feb 01 '20 at 17:12
  • I would strongly recommend that you start using an IDE (e.g. IntelliJ or Eclipse), those make programming much more fun :) – JavaMan Feb 02 '20 at 10:24
  • Normally, if I weren't using C/C++, then I would just use Java Swing, which has no external dependencies/modules like JavaFX. But since I must use JavaFX, then I may be forced to use other tools like that, unfortunately. – C. Dunn Feb 02 '20 at 12:31

0 Answers0