OSGi bundle reloading and "Application launch must not be called more than once"

info at cuhka.com info at cuhka.com
Fri Oct 2 13:43:13 UTC 2015


I'm using OSGi (Apache Felix) to develop my application. The bundle's  
activator is as follows:

	@Override
	public void start(BundleContext context) throws Exception {
		new Thread(() -> Application.launch(Desktop.class), "JavaFX Desktop  
launcher").start();
	}

	@Override
	public void stop(BundleContext context) throws Exception {
		Platform.exit();
	}

The new Thread() is because Application.launch blocks the thread (can  
it be avoided?).

However, the main problem is when I stop a bundle, do an update and  
try to start it again. Unless I quit the entire OSGi container I get  
the following stacktrace:

g! Exception in thread "JavaFX Desktop launcher"  
java.lang.IllegalStateException: Application launch must not be called  
more than once
	at  
com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:162)
	at  
com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:143)
	at javafx.application.Application.launch(Application.java:191)

While I understand this in a regular situation, it is kind of annoying  
in a environment such as OSGi. I would have thought that calling  
Platform.exit() in the activator's stop() method would have done the  
trick, but obviously it doesn't.

Is there a way to completely stop the JavaFX framework in the stop()  
method so that a subsequent call to start() will be capable of  
starting a new application?




More information about the openjfx-dev mailing list