There is a comment on the answer to this question:
How to create splash screen as a Preloader in JavaFX standalone application?
system property javafx.preloader=classname
seems to work too.
I didn't try it, but perhaps you could try setting that property and just launching your main app via the public Application.launch(appClass, args)
API and perhaps the preloader will launch first.
Looking into the code for Application.launch
, it seems that this would work. Here is the code which is eventually invoked, copied from the Java 8 source:
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);
}
So you should be able to launch an app with a preloader using:
System.setProperty("javafx.preloader", "my fully qualified preloader class name");
Application.launch(myMainClass, args);