OSGI Bundle vs jar依赖 [英] OSGI Bundle vs jar dependency

查看:287
本文介绍了OSGI Bundle vs jar依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试理解以下

    <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>

dal工件本身的包装指定为包装:

The dal artifact itself has packaging specified as bundle as:

<packaging>bundle</packaging>

现在当我部署dal工件时,我看到它作为一个jar发布在repo中(带有在其中表现出来)。在这种情况下,我对dal的依赖应该是什么。它应该是捆绑式还是罐型?如果我正在做OSGI,我认为将类型指定为bundle。它是否正确?或者,我可以在这里有一个jar依赖吗?

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?

推荐答案

当你在Maven中声明一个依赖项时,你只能依赖一个普通的Jar,而不是一个bundle,因为Maven没有认识到OSGi环境的限制。

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.

看到这个问题:

为什么maven找不到osgi包依赖?

在编译项目时,您不必担心(但应该!)关于OSGi环境......例如,如果您尝试使用的是软件包,它不会抱怨由您依赖的bundle导出....

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....

当您尝试在OSGi容器中部署捆绑包时,如果您正确地声明了对dal的依赖关系'你使用的包,当然包括版本(通常你应该留给maven-bundle-plugin为你做的基于你的POM),它只会在有捆绑的情况下解决在容器中导出正确版本(或版本范围)中所需的包。

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).

考虑到'dal'似乎已经是一个包,你只需要制作一定要将你的捆绑包和'dal'一起部署,一切都会正常工作。

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.

但是,如果你错误地添加了对'dal'私有包的依赖,虽然Maven很乐意为你编译它,当你在OSGi中抛出它时,你会受到一个令人讨厌的布线异常的欢迎:)

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 :)

注意一个bundle只是一个普通的jar其中包含清单中的OSGi元数据(Bundle-SymbolicName,Bundle-Version等)。因此,如果您不使用OSGi,捆绑包将像任何其他jar一样工作。

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:

type" bundle是什么意思?在maven依赖?

这篇关于OSGI Bundle vs jar依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆