Val*_*csa 6 java javafx preloader java-9 javafx-9
在Java 8中,我可以使用以下方法使用预加载器启动JavaFX应用程序:
LauncherImpl.launchApplication(WindowMain.class, WindowMainPreloader.class,
new String[]{...});
Run Code Online (Sandbox Code Playgroud)
我更喜欢从代码开始,如上所述,而不是使用部署配置,因为我不希望每次启动应用程序时都启动图形界面,但只有在计算出应用程序运行的某些代码之后GUI模式.
我使用的是"com.sun.javafx.application.LauncherImpl"类,但显然在Java 9中,所有以"com.sun"开头的类都被删除了.那么,如何在Java 9中使用预加载器启动应用程序?
对这个问题的答案有评论:
系统属性
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);
}
Run Code Online (Sandbox Code Playgroud)
因此,您应该能够使用预加载器启动应用程序:
System.setProperty("javafx.preloader", "my fully qualified preloader class name");
Application.launch(myMainClass, args);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1456 次 |
| 最近记录: |