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