I’ve taken the task of migrating the Ikonli build from Java 8 to Java11/JavaFX11. While most of the changes required are explained at https://guides.gradle.org/building-java-9-modules/ I’m experiencing some trouble with the run task provided by the application plugin.
Running the application from the command line (using gradlew run) yields the following error on screen
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:566)
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:566)
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:834)
Caused by: java.lang.IllegalStateException: Location is not set.
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2459)
at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:2435)
at org.kordamp.ikonli.sampler.javafx/org.kordamp.ikonli.sampler.javafx.Sampler.start(Sampler.java:81)
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(Native Method)
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)
Exception running application org.kordamp.ikonli.sampler.javafx.Sampler
This is because an FXML resource file was not found. The source tree is set as
That’s what I thought. I also added a --patch-module instruction but it didn’t work either.
Coincidentally, what would be the new source tree conventions for dealing with this situation? (classes and resources under the same package) I woldn’t like to patch every single module just to gain access to a resource file.
There is no usage of resources files in the guide, only classes. As you can see, the module-path already includes both classes and resources, so the snippet is already wrong. Adding a --patch-module instruction doesn’t help either
Even tried grabbing hold of the Module and querying its classloader. Doesn’t work either.
Packaging and running the application as a modular JAR is already too late. I could run the application with Gradle using pre Java9. I can run the application from the build using Maven without any extra configuration nor requiring an extra step to pack and run as an external Java process .
The problem as you said is likely related to split packages but I get no problem report when running java9c from the gradle-java9-collision plugin. Granted, the plugin might be missing something, still it has been pretty accurate so far.
Results in the application showing the expected result. Thus the problem lies when running the application from within Gradle. How can this be fixed to make it work? Thanks
I am facing a similar issue. As @Andres_Almiray said, it runs fine from the terminal with the java command while it fails with the Gradle application plugin.
unfortunately, I have the same problem. It only occurs when I start it via the IDE (IntelliJ). But if I build a .jar file from it, the resources will be found. Very strange!
The message resources are not found either.
java.lang.IllegalStateException: Location is not set.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2459) ~[javafx-fxml-11-win.jar:?]
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2435) ~[javafx-fxml-11-win.jar:?]
I have my application powered up in a spring-boot context. Maven spring: run and java -jar spring-boot-jfx.jar run smoothly.
You must define a module-info.java file and move the HelloFx class to a package instead of using the default package. Sadly the Gradle sample provided by Gluon is of low quality as it assumes a very basic setup.