Questions tagged [osgi]

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.

6201 questions
39
votes
4 answers

Best technique for getting the OSGi bundle context?

Each bundle in my OSGi project has its own BundleActivator, which I think is normal. This gets passed the current BundleContext, which is useful to have around for getting service references and whatnot. However, from classes in my bundle, how can I…
xconspirisist
  • 1,451
  • 2
  • 13
  • 26
39
votes
1 answer

How can I run a subprocess in Equinox with dynamic bundle installation?

I have a Java application that runs in OSGi/Equinox. From this application, I need to spawn Java subprocesses (e.g. via ProcessBuilder.start()) that run in OSGi/Equinox as well in order to handle class loading correctly. The subprocess will require…
mapeters
  • 1,067
  • 7
  • 11
38
votes
1 answer

Full Android support for OSGi bundles

This topic explains how you can transform an OSGI framework to run on android. Then it gives tips to convert android packages as OSGI bundles capable of calling android API. At the current stage, the only thing these Android OSGI bundles cannot do…
slash33
  • 899
  • 1
  • 11
  • 17
38
votes
6 answers

Dependency Injection in OSGI environments

First some background: I'm working on some webapp prototype code based on Apache Sling which is OSGI based and runs on Apache Felix. I'm still relatively new to OSGI even though I think I've grasped most concepts by now. However, what puzzles me is…
ilikeorangutans
  • 1,753
  • 1
  • 11
  • 14
37
votes
4 answers

Scala in OSGI container?

How can I code my bundle in Scala and then deploy it into OSGI container? Do I compile it into "java" first or can i deploy scala straight into OSGI and use some kind of bundles to recognize it? Any pointers would be great. Currently I am using…
Andriy Drozdyuk
  • 58,435
  • 50
  • 171
  • 272
37
votes
5 answers

OSGi: Blueprint vs. Spring DM

I am a little bit confused about Blueprint and Spring DM: From what I think is true: Spring DM is a framework defined by Spring Source Blueprint is a framework defined by the OSGi Alliance Blueprint has "taken" many of it's ideas from Spring…
Frizz
  • 2,524
  • 6
  • 31
  • 45
35
votes
1 answer

Better handling of Thread Context ClassLoader in OSGi

I've been using OSGi for a while now and I have various solutions to the problems I encountered. I wanted to revisit one of these and see if people had come up with different solutions. One of the most common issues I have with OSGi (Equinox 3.4.2)…
omerkudat
  • 9,371
  • 4
  • 33
  • 42
34
votes
1 answer

Installing a new version of Groovy on my OSGi environment makes my bundle import it, though it shouldn't

I have a little bundle that uses Groovy to interpret scripts. The manifest Import-Package instruction looks like this: Import-Package: groovy.util;version="[1.8,2)" The version range above clearly states the import version must be between 1.8…
Renato
  • 12,940
  • 3
  • 54
  • 85
32
votes
7 answers

Can Spring Boot be used with OSGi? If not, any plans to have an OSGi Spring Boot?

Can Spring Boot be used with OSGi? If not, any plans to have an OSGi Spring Boot (Apache Felix or Eclipse Equinox)? In my opinion, cloud applications must be highly modular and updatable like OSGi offers.
user3646774
  • 652
  • 2
  • 7
  • 11
30
votes
10 answers

How to make code modular?

I have some Java programs, now I want to find out whether it is modular or not, if it is modular then up to what extent, because modularity can never be binary term i.e. 0 or 1. How do I decide that particular code is modular upto this much extent.…
user175498
29
votes
3 answers

Programmatically Start OSGi (Equinox)?

I'd like to be able to easily start an OSGi framework (preferably Equinox) and load up any bundles listed in my pom from a java main. Is this possible? If so, how? It seems like the pax tools would do this, but I can't seem to find any…
javamonkey79
  • 17,443
  • 36
  • 114
  • 172
29
votes
2 answers

Whats the deal with private packages?

I have been working with OSGi for a while now, but I still don't understand something about private packages. An exported package is a package with is visible to other bundles An imported package is a package which is imported by a bundle…
Mirco
  • 2,940
  • 5
  • 34
  • 57
28
votes
3 answers

How to deploy OSGi apps and dependencies?

OSGi seems to have an excellent benefit of having small deployable artifacts by not wrapping dozens of JAR dependencies into a lib directory. However, I can't find anything that tells me an easy, reliable way to deploy dependencies to a container.…
jcalvert
  • 3,628
  • 2
  • 19
  • 13
28
votes
2 answers

Trouble understanding the whole OSGi web eco system

I am pretty new to the whole Java and OSGi world and I have trouble understanding the eco system of a OSGi web application. To be more precise I am at the moment trying to understand how all the parts of the eco system are related to each…
Jens
  • 20,533
  • 11
  • 60
  • 86
27
votes
2 answers

manifest first OSGi build with gradle - migrating from ant to Gradle

Is there manifest first http://wiki.osgi.org/wiki/Tooling_Approaches gradle plugin for OSGi? Or how to do it with gradle? There's big old project for OSGi container with many project having complicated relation declared in MANIFEST.MF. The build is…
Paul Verest
  • 60,022
  • 51
  • 208
  • 332