Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing resources from OSGi bundle

Tags:

java

bundle

osgi

With the import mechanism in OSGi, it is straightforward to import packages from another bundle. However, I have been unsuccessful in importing resources that exist in the "root" of the bundle.

Is it at all possible to import resources that aren't package scoped in to another bundle?

What I would like to achieve is this:

Bundle A has a file resource in the "root"

Bundle B imports bundle A:s packages and resources. Through bundle B:s ClassLoader, I'd like to be able to load the resource in bundle A as if it existed in Bundle B.

like image 421
Christer Fahlgren Avatar asked Sep 27 '11 04:09

Christer Fahlgren


People also ask

What is difference between JAR and OSGi bundle?

The key difference with OSGi is that a JAR is now all private, adding metadata in the manifest makes it a bundle that can safely share with other bundles. OSGi makes sure violations are detected ahead of time.

How do I run OSGi bundle?

Procedure. Install the plug-in bundle into the Eclipse Equinox OSGi framework with the OSGi console. Start the Eclipse Equinox framework with the console enabled. Install the plug-in bundle in the Equinox console.

What is the use of OSGi bundle?

An OSGi bundle JAR file contains a JAR manifest file. This file contains metadata that enables the OSGi Framework to process the modular aspects of the bundle. Describes the version of the bundle and enables multiple versions of a bundle to be active concurrently in the same framework instance.

What is an OSGi bundle?

In OSGi, a single component is called a bundle. Logically, a bundle is a piece of functionality that has an independent lifecycle – which means it can be started, stopped and removed independently. Technically, a bundle is just a jar file with a MANIFEST. MF file containing some OSGi-specific headers.


1 Answers

Resources in the root of a bundle are in the "default" package, which cannot be imported or exported.

If you really must access the resources via classloader, you need to move them into a package and export that package. Otherwise you can use Bundle.getEntry() to read resources from any location of any bundle.

like image 159
Neil Bartlett Avatar answered Nov 15 '22 14:11

Neil Bartlett