4

ControlsFX website says:

If you want to play with the ControlsFX sample application, simply download the ControlsFX release and run the following command on the command prompt (be sure to replace the * with the actual version number of FXSampler and ControlsFX-samples):

java -jar controlsfx-samples-*.jar

I've downloaded ControlsFX 9.0.0 which is said to be for users of Java 9 and later.

When I run java -jar controlsfx-samples-9.0.0.jar I get

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

But that's OK, as according to Run HelloWorld using JavaFX 11 guide, I have to add modules.

So I try java --module-path "C:\Program Files\Java\javafx-sdk-11\lib" --add-modules=javafx.controls -jar controlsfx-samples-9.0.0.jar and I get

Missing JavaFX application class fxsampler.FXSampler

I execute all commands from controlsfx-9.0.0 directory which contains controlsfx-9.0.0.jar, controlsfx-samples-9.0.0.jar and fxsampler-1.0.10.jar.

Output of java -version for me is:

openjdk version "11.0.1" 2018-10-16
OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)

Any comments and suggestions are appreciated.
Thanks in advance.

EDIT:
After following Slaw's advice and running java --module-path "C:\Program Files\Java\javafx-sdk-11\lib" --add-modules=javafx.controls,javafx.fxml,javafx.web -jar controlsfx-samples-9.0.0.jar I get

Initialising FXSampler sample scanner...
        Discovering projects...
                Found project 'ControlsFX', with sample base package 'org.controlsfx.samples'
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.NoClassDefFoundError: Could not initialize class impl.org.controlsfx.version.VersionChecker
        at org.controlsfx.control.ControlsFXControl.(ControlsFXControl.java:35)
        at org.controlsfx.control.WorldMapView.(WorldMapView.java:93)
        at org.controlsfx.samples.HelloWorldMapView.(HelloWorldMapView.java:55)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
        at java.base/java.lang.Class.newInstance(Class.java:584)
        at fxsampler.util.SampleScanner.discoverSamples(SampleScanner.java:86)
        at fxsampler.FXSampler.start(FXSampler.java:106)
        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)
        at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
        ... 1 more
Exception running application fxsampler.FXSampler
DfM
  • 529
  • 6
  • 19
  • Similar issue as this other SO thread ? [JavaFX packaging: NoClassDefFoundError](https://stackoverflow.com/questions/52761836/javafx-packaging-noclassdeffounderror) – keybored Oct 18 '18 at 12:16
  • @keybored Well, it had been similar before I've added `--add-modules`. And the thread says that the problem was in absence of JavaFX in JDK 11, but https://openjfx.io/ states that ControlsFX supports JavaFX 11, so I guess I have another problem. – DfM Oct 18 '18 at 12:29
  • 1
    You've added `javafx.controls` which will also pull in `javafx.graphics` and `javafx.base`, but do the samples need any of the other modules? Such as `javafx.fxml` or `javafx.web`? – Slaw Oct 18 '18 at 12:49
  • @Slaw You we right. Now I get another exception. I've updated the post. – DfM Oct 18 '18 at 13:17

1 Answers1

2

Fixed in PR #720. So new Maven artifacts will incorporate the fix.

Full issue history can be seen here.

DfM
  • 529
  • 6
  • 19
  • How does a new Maven artifact help with running it from the command line? – dmolony Nov 26 '18 at 06:16
  • @dmolony All the jars you download from ControlsFX website are maven artifacts just packed in a zip archive. You can check yourself by downloading [current archive](http://fxexperience.com/downloads/controlsfx-9-0-0/) and comparing the jars in it with [Maven artifacts](https://search.maven.org/search?q=org.controlsfx). – DfM Nov 28 '18 at 12:57
  • It still doesn't work. I just downloaded the 9.0.0 jars, and gave the command as per the instructions. Error: Could not find or load main class fxsampler.FXSampler – dmolony Jan 15 '19 at 08:25
  • Then I tried it with the instructions above. Error occurred during initialization of boot layer java.lang.module.FindException: Module javafx.controls not found – dmolony Jan 15 '19 at 08:37
  • 1
    @dmolony 9.0.0 jars are NOT compatible with JavaFX 11. You have to wait for the new ones. As stated on https://github.com/controlsfx/controlsfx: "For users of Java 11 and later, download will be coming soon!" – DfM Jan 23 '19 at 12:30
  • As the OP's question was about Java 11, and because the accepted answer (this one) says 'Fixed in PR #720', it seemed safe to assume that it was fixed for Java 11. – dmolony Jan 24 '19 at 08:44
  • @dmolony developers of ControlsFX have made a fix, so that ControlsFX can run on JDK 11, but they haven't built artifacts with that fix included. If you want, you can build ControlsFX on your own. – DfM Jan 24 '19 at 16:59