The OSGi (Open Service Gateway Initiative) framework is a module system and service platform for the Java programming language that implements a complete and dynamic component model.
The Open Service Gateway Initiative or commonly named OSGi is a specification for a Java component framework with enforced modularity. It provides a comprehensive model to build applications out of smaller, reusable parts. Though it works with any Java code, its advantages are best obtained by using its strong modularity. OSGi encapsulates each JAR in its own class loader and selectively exports packages. OSGi then links each module to the package/module versions they need thereby addressing JAR hell since multiple versions of the same package/module are allowed in OSGi. It also provides for private packages, i.e. packages not visible to any other module.
OSGi modules are normal JAR files with their metadata in the manifest, expressing the module's requirements and capabilities (e.g. import/export package, but extendable). OSGi modules are reified in runtime and have a life cycle. They can be installed, resolved, started, stopped, and uninstalled. Module code can run at start/stop time and an extensive event mechanism is the basis for numerous middleware that simplifies writing modules.
Popular Java factory/DI models collide with strong modularity (these model require implementation class names to be known outside their module). To alleviate this clash, the OSGi provides a modular solution to finding and sharing instances between modules, the so called (µ)services model. A consequence of the strong modularity is that OSGi can hot-swap modules without restarting the application. This is very useful during development but can also be used in server based applications.
All popular Java Application servers are either built on top of OSGi or fully support its module specification. The two popular open source OSGi frameworks are Felix and Equinox. Equinox is the foundation on which Eclipse is built. For the Java embedded world there are implementations like Knopflerfish, Concierge, Prosyst (commercial) as well as several private implementations.
The OSGi Alliance is a worldwide consortium of technology innovators that advances a proven and mature process to create open specifications that enable the modular assembly of software built with Java technology. The OSGi Service Platform facilitates the componentization of software modules and applications and assures interoperability of applications and services over a variety of networked devices.