对这个问题的答案有评论:
如何在 JavaFX 独立应用程序中创建启动画面作为预加载器?
系统属性javafx.preloader=classname
似乎也有效。
我没有尝试过,但也许您可以尝试设置该属性并通过公共Application.launch(appClass, args)
API 启动您的主应用程序,也许预加载器将首先启动。
查看 的代码Application.launch
,这似乎可行。下面是最终调用的代码,从 Java 8 源代码复制而来:
public static void launchApplication(final Class<? extends Application> appClass,
final String[] args) {
Class<? extends Preloader> preloaderClass = savedPreloaderClass;
if (preloaderClass == null) {
String preloaderByProperty = AccessController.doPrivileged((PrivilegedAction<String>) () ->
System.getProperty("javafx.preloader"));
if (preloaderByProperty != null) {
try {
preloaderClass = (Class<? extends Preloader>) Class.forName(preloaderByProperty,
false, appClass.getClassLoader());
} catch (Exception e) {
System.err.printf("Could not load preloader class '" + preloaderByProperty +
"', continuing without preloader.");
e.printStackTrace();
}
}
}
launchApplication(appClass, preloaderClass, args);
}
因此,您应该能够使用以下方式启动带有预加载器的应用程序:
System.setProperty("javafx.preloader", "my fully qualified preloader class name");
Application.launch(myMainClass, args);