Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OSGI Bundle vs jar dependency

I'm trying to understand the difference between the following

    <dependency>
        <groupId>com.myspace.order</groupId>
        <artifactId>dal</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </dependency>

AND

    <dependency>
        <groupId>com.myspace.order</groupId>
        <artifactId>dal</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <type>bundle</type>
    </dependency>

The dal artifact itself has packaging specified as bundle as:

<packaging>bundle</packaging>

Now when I deploy the dal artifact, I see it published in the repo as a jar (with a manifest within it). In this case, what should my dependency on dal be. Should it be of type bundle or jar? If I am doing OSGI, I assume way would be to have the type specified as bundle. Is this correct? Or, can I just have a jar dependency here?

like image 251
Sudoer Avatar asked Feb 16 '13 18:02

Sudoer


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.

What is a OSGi bundle?

OSGi is a Java framework for developing and deploying modular software programs and libraries. Each bundle is a tightly coupled, dynamically loadable collection of classes, jars, and configuration files that explicitly declare their external dependencies (if any).

What is true about OSGi bundles?

OSGi bundles allow versioning of code Two different applications might have different version requirements on the same library. OSGi allows both versions to be deployed simultaneously, and both applications can be satisfied.

What is OSGi bundle in AEM?

An OSGi bundle is a Java™ archive file that contains Java code, resources, and a manifest that describes the bundle and its dependencies. The bundle is the unit of deployment for an application. This article is meant for developers wanting to create OSGi service or a servlet using AEM Forms 6.4 or 6.5.


1 Answers

When you declare a dependency in Maven, you can only depend on a normal Jar, not a bundle, because Maven does not recognize the OSGi environment restrictions.

See this question:

Why can't maven find an osgi bundle dependency?

At the time you compile your project, you don't need to worry (but should!) about the OSGi environment yet... for example, it will not complain if you try to use packages not exported by the bundle you're depending upon....

When you try to deploy your bundle within a OSGi container, if you correctly declared your dependencies on the 'dal' packages you use, including of course the version (which usually you should leave for the maven-bundle-plugin to do for you based on your POM), it will only be resolved if there's a bundle within the container which exports the required packages in the right version (or version range).

Considering that 'dal' seems to be a bundle already, you just have to make sure to deploy the your bundle and 'dal' together and everything will work fine.

However, if you by mistake added a dependency on a private package of 'dal', although Maven will happily compile it for you, when you thrown it in OSGi you will be greeted by a nasty wiring exception :)

Notice that a bundle is just a normal jar which contains OSGi metadata in the manifest (Bundle-SymbolicName, Bundle-Version etc). So if you don't use OSGi, a bundle will work as any other jar.

But anyway, if you want some more info, check this question:

What is the meaning of type "bundle" in a maven dependency?

like image 86
Renato Avatar answered Oct 21 '22 02:10

Renato