如果要使用ControlsFX示例应用程序,只需 下载ControlsFX发行版,并在 命令提示符(请务必将*替换为实际版本 FXSampler和ControlsFX样本的数量):
java -jar controlsfx-samples-*.jar
我已经下载了ControlsFX 9.0.0,据说该版本适用于Java 9及更高版本的用户。
运行java -jar controlsfx-samples-9.0.0.jar
时我会得到
错误:找不到或加载主类fxsampler.FXSampler
引起原因:java.lang.NoClassDefFoundError:javafx / application / Application
但是没关系,根据Run HelloWorld using JavaFX 11 guide,我必须添加模块。
所以我尝试java --module-path "C:\Program Files\Java\javafx-sdk-11\lib" --add-modules=javafx.controls -jar controlsfx-samples-9.0.0.jar
并得到
缺少JavaFX应用程序类fxsampler.FXSampler
我从controlsfx-9.0.0
目录执行所有命令,其中包含controlsfx-9.0.0.jar
,controlsfx-samples-9.0.0.jar
和fxsampler-1.0.10.jar
。
java -version
对我的输出是:
openjdk版本“ 11.0.1” 2018-10-16
OpenJDK运行时环境18.9(内部版本11.0.1 + 13)
OpenJDK 64位服务器VM 18.9(内部版本11.0.1 + 13,混合模式)
任何评论和建议都值得赞赏。
预先感谢。
编辑:
跟随Slaw's advice并运行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
之后,我得到了
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