Osgi Felix maven bundle插件可传递依赖性问题

Osgi Felix maven bundle插件可传递依赖性问题,osgi,maven-plugin,apache-felix,Osgi,Maven Plugin,Apache Felix,我是OSGI新手,正在尝试部署我的第一个应用程序。我的pom中有一个spring依赖项。在部署时,我意识到Felix运行时需要所有可传递的依赖项才能正确安装捆绑包。从那以后,我一直在努力解决这个问题。我尝试过嵌入依赖项和嵌入传递选项,但没有成功。这是我的pom <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:sc

我是OSGI新手,正在尝试部署我的第一个应用程序。我的pom中有一个spring依赖项。在部署时,我意识到Felix运行时需要所有可传递的依赖项才能正确安装捆绑包。从那以后,我一直在努力解决这个问题。我尝试过嵌入依赖项和嵌入传递选项,但没有成功。这是我的pom


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.test</groupId>
    <artifactId>taxonomydaobundle</artifactId>
    <version>1.0.0</version>
    <packaging>bundle</packaging>
    <name>Taxonomy Dao Bundle</name>
    <url>http://maven.apache.org</url>
    <repositories>
        <repository>
            <id>fusesource</id>
            <url>http://repo.fusesource.com/maven2</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
            </releases>
        </repository>
        <repository>
            <id>apache-public</id>
            <url>https://repository.apache.org/content/groups/public/</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
            </releases>
        </repository>
    </repositories>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.test</groupId>
            <artifactId>taxonomymodelbundle</artifactId>
            <version>1.0.0</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring</artifactId>
            <version>2.5.5</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.0.1</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Export-Package>com.test.taxonomy.api.*;version=1.0.0
                        </Export-Package>
                        <Import-Package>com.test.taxonomy.message.*;version=1.0.0,
                            *
                        </Import-Package>
                        <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
                        <Embed-Transitive>true</Embed-Transitive>
                    </instructions>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

如果有人能分享他们在这方面的经验,我将不胜感激


-多亏了

在OSGi环境中,部署所需库的常用方法是将它们作为自己的捆绑包进行部署。我知道,如果库未启用OSGi,并且与OSGi容器中的其他bundle无关,则嵌入库是最常用的选项

因此,如果您的bundle依赖于其他库,您应该首先查看这些库是否支持OSGi,并将它们作为自己的bundle安装在OSGi容器中

如果您使用的库未启用OSGi,您可以查看一些提供这些库的支持OSGi的包装包的地方,例如

Spring支持OSGi——您应该可以自己部署这些捆绑包。我也建议你看看。如果您构建了支持Spring的捆绑包,您还可以从已经准备好这些捆绑包的OSGi容器开始。我制作了一个很好的Expirence,它基于OSGi容器是免费的,还有更多的商业支持


因此,尽管我没有回答你们的具体问题,但我还是分享了我的一些经验,并希望这能对你们有所帮助。祝你好运

maven bundle插件的可传递依赖项管理中存在一个bug,其中一些可能不存在。我怀疑这就是它试图拉拢黑森时所发生的事情

我支持K.Claszen关于在springsource或fusesource上查找捆绑包版本的想法,但是如果有无法找到的捆绑包,maven捆绑包插件提供了一个新的解决方案。这个目标将导致bundle插件为应用程序的所有可传递依赖项创建bundle。然后可以使用在springsource/fusesource中找不到的。完成此操作后,您就不需要将jar嵌入到包中,这将使其他包也可以使用它们


您可能遇到的一个警告是,需要部署bundle,以便在其依赖项之一之前不部署任何bundle。在过去,我使用EclipseVirgo服务器来解决这个问题。它允许您将所有捆绑包放在存储库中,并让服务器确定部署顺序。

使用-X选项运行Maven,这将使捆绑包插件打印它认为的依赖关系树

[DEBUG] Will bundle the following dependency tree
org.springframework:spring-remoting:jar:2.0.8:runtime
   aopalliance:aopalliance:jar:1.0:compile
   commons-httpclient:commons-httpclient:jar:3.0.1:compile
      junit:junit:jar:3.8.1:compile
      (commons-logging:commons-logging:jar:1.0.3:compile - omitted for conflict with 1.1)
      commons-codec:commons-codec:jar:1.2:compile
   commons-logging:commons-logging:jar:1.1:compile
      log4j:log4j:jar:1.2.12:compile
      logkit:logkit:jar:1.0.1:compile
      avalon-framework:avalon-framework:jar:4.1.3:compile
      (javax.servlet:servlet-api:jar:2.3:compile - omitted for conflict with 2.4)
   hessian:hessian:jar:3.0.20:compile
不幸的是,您无法调整项目的pom depdnencyManagement部分以删除可选依赖项,因为maven bundle插件忽略了这一点

根据它的描述,它将访问所有可选的依赖项。
我能提供的唯一建议是找到那些可选的工件,并确保Maven能够解决它们。

@Claszen..感谢您的回复。我正在使用fuse esb作为工具来测试我的应用程序。根据您的评论,我有几个后续问题。您提到直接安装支持OSGI的捆绑包,而不是嵌入它们。这是否意味着您从spring DM存储库手动复制spring bundleorg.springframework.spring-library,并使用命令行/felix管理工具将其安装到Fuse中?它如何解决可传递依赖关系?例如,spring将在内部依赖hibernate JAR。这是否意味着您也需要手动安装hibernate捆绑包?@Sahamik I将我的捆绑包聚合到功能中,以便将它们一起安装。请看一下FUSE ESB文档的特性一章。没有办法自动安装可传递依赖项-您必须自己处理它们。一个特性不是OSGi标准—其他容器可能会提供其他机制,使您能够一次安装一组捆绑包。Spring应该是FUSE ESB设置的一部分-据我所知hibernate还没有准备好OSGi-您将在internet上的OSGi中找到启用hibernate的提示。
[DEBUG] Will bundle the following dependency tree
org.springframework:spring-remoting:jar:2.0.8:runtime
   aopalliance:aopalliance:jar:1.0:compile
   commons-httpclient:commons-httpclient:jar:3.0.1:compile
      junit:junit:jar:3.8.1:compile
      (commons-logging:commons-logging:jar:1.0.3:compile - omitted for conflict with 1.1)
      commons-codec:commons-codec:jar:1.2:compile
   commons-logging:commons-logging:jar:1.1:compile
      log4j:log4j:jar:1.2.12:compile
      logkit:logkit:jar:1.0.1:compile
      avalon-framework:avalon-framework:jar:4.1.3:compile
      (javax.servlet:servlet-api:jar:2.3:compile - omitted for conflict with 2.4)
   hessian:hessian:jar:3.0.20:compile