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
18
votes
5 answers

Implementing dynamic plugins in Java

I'd like to implement a dynamic plugin feature in a Java application. Ideally: The application would define an interface Plugin with a method like getCapabilities(). A plugin would be a JAR pluginX.jar containing a class PluginXImpl implementing…
Chris Conway
  • 55,321
  • 43
  • 129
  • 155
18
votes
1 answer

Which version of OSGi is implemented by which version of Eclipse/Equinox?

We are looking for a table which matches Eclipse/Equinox release versions to the corresponding OSGi Service Platform specification release version. Eclipse/Equinox wiki doesn't have any info on this in a structured form.
Ilya Shinkarenko
  • 2,134
  • 18
  • 35
18
votes
3 answers

How to find and stop all currently running threads?

I have an multiple-threaded java project and I want to add a method stop() to stop all the running threads. The problem is that this project is developed by someone else, and I am not familiar with how it implements multiple threads. What I know is…
Li'
  • 3,133
  • 10
  • 34
  • 51
18
votes
4 answers

How to get classloader for a bundle in equinox?

I have read a lot of equinox code for this, but still can't figure out a non-hacky way of getting the classloader for a osgi bundle in eclipse equinox setup. Is there one?
Suraj Chandran
  • 24,433
  • 12
  • 63
  • 94
18
votes
3 answers

Should I use POM first or MANIFEST first when developing OSGi application with Maven?

There are two main approaches when developing an OSGi application with Maven: POM-first and MANIFEST first. I'm looking for an answer that is in a form of a table that shows pros and cons of each method. To be more specific, I would also like to…
Archimedes Trajano
  • 35,625
  • 19
  • 175
  • 265
18
votes
3 answers

Spring unable to locate OSGi namespace handler

I have a spring MVC projet that runs on eclipse virgo OSGi platform. When I attempt to import an OSGi service using tag I get the following exception : Servlet /Web threw load() exception…
Houcem Berrayana
  • 3,052
  • 22
  • 40
17
votes
2 answers

OSGi memory management

I have theoretical question about OSGi memory management. Let’s say we have some OSGi container (Felix for instance), and let’s suppose I created some bundle with memory leak. And here are some questions that I have: Is there any way to limit…
Sebastian Łaskawiec
  • 2,667
  • 15
  • 33
17
votes
3 answers

Where to place module-info.java using Java 9?

I have an OSGI application and I have around 30 bundles (jar files). Today I decided to see how it works/if it works with Java 9. So I started my application and got WARNING: An illegal reflective access operation has occurred WARNING: Illegal…
Pavel_K
  • 10,748
  • 13
  • 73
  • 186
17
votes
3 answers

Using Java 7 Comparators in Java 8

Situation I have an OSGi project that I'm trying to migrate to Java 8. In my project, I have dependencies to third party libraries that I "OSGi-fied" (by just adding the MANIFEST.MF file and putting metadata into it). These libraries are checked out…
thobens
  • 1,729
  • 1
  • 15
  • 34
17
votes
14 answers

The activator for bundle is invalid

I'm trying to create a simple plugin in eclipse. When I run the application, I see this error in log file: org.osgi.framework.BundleException : The activator for bundle org.x.y.Activator for bundle org.x.y is invalid. Do you have any idea about…
penguru
  • 4,342
  • 11
  • 46
  • 56
16
votes
1 answer

What's the difference between features in Karaf and OBR

I am looking into ways to deploy and update an OSGI (Karaf, specifically) application. It seems that there are several options. One is to use The OSGi Bundle Repository (OBR), another is to use Features in Karaf, and the third is to use Karaf…
Oleksi
  • 12,947
  • 4
  • 56
  • 80
16
votes
3 answers

How is the OSGi bundle start level defined?

How is the OSGi bundle start level defined? I am using Apache felix and would like to persist the start level across framework executions. I do not anticipate a need to change the start level of a bundle very frequently at all an an entry in…
xconspirisist
  • 1,451
  • 2
  • 13
  • 26
16
votes
14 answers

Quick and easy way to test OSGi bundles

Currently, I am working on a new version control system as part of a final year project at University. The idea is to make it highly adaptable and pluggable. We're using the OSGi framework (Equinox implementation) to manage our plug ins. My problem…
fluffels
  • 4,051
  • 7
  • 35
  • 53
16
votes
3 answers

How do I access a file inside an OSGi bundle?

I am new to OSGi and created an OSGi-bundle which I run in the Apache Felix OSGi-container. There is a file resource contained in the bundle, which I need to pass to a method as a java.io.File. To instantiate a File-object, either an URI in the…
mtsz
  • 2,725
  • 7
  • 28
  • 41
16
votes
3 answers

Is separate OSGI bundles for api and implementation common practice?

I have a class with dependencies which I want to hot deploy without restarting the dependencies. The class has an interface but there's only one concrete implementation. Initially I created a single bundle with exported the interface and registered…
Thomas Rynne
  • 397
  • 2
  • 10