I’m looking for a best practice on shutting down an OSGi container.
Currently we are using a small launcher app which calls EclipseStarter.startup() and installs some core bundles. After that the launcher terminates.
When the test GUI (running as a bundle) is closed it calls a System.exit(0) to shutdown the container, but there must be a more elegant solution than this.
Thanks
Please, don’t use System.exit(0) to shut down an OSGi framework. You should to it by stopping the bundle with the ID 0, the System bundle. This way, you give all bundles a chance to shut down in an orderly manner (e.g. to free resources etc).
The OSGi specification defines the following (Core Specification, R4.x, 4.2.6 Stopping a Framework).
In that chapter a detailed description is given what happens when a framework is shut down.
The system bundle resp. the framework object is also defined (chapter 4.6 The System Bundle):
The OSGi spec is available for free at the OSGi Alliance’s website (http://www.osgi.org/Specifications/HomePage).