Felix maven-bundle-plugin传递依赖问题

时间:2011-06-10 07:02:05

标签: osgi maven-plugin apache-felix

我是OSGI的新手并尝试部署我的第一个应用程序。我的pom中有一个春天的依赖。在部署时我意识到Felix运行时需要所有传递依赖项才能正确安装bundle。从那以后,我有点难以解决这个问题。我尝试过嵌入式依赖和嵌入式传递选项,但没有运气。这是我的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>

最初,我正在尝试 mvn install ,但它只包含直接依赖项,而不是传递依赖项。在阅读了felix maven插件文档后,我尝试了 mvn org.apache.felix:maven-bundle-plugin:bundleall 。但是,执行失败,因为它无法从其使用的存储库中获取所需的jar文件。查看日志,我可以看到它指的是http://repo1.maven.org/maven2存储库,它没有所需的版本。对于例如这个来自粗麻布3.1.3,以及其他。


[INFO] Unable to find resource 'hessian:hessian:pom:3.1.3' in repository central
 (http://repo1.maven.org/maven2)

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

-Thanks

3 个答案:

答案 0 :(得分:3)

在OSGi环境中,部署所需库的常用方法是将它们部署为自己的bundle。如果库未启用OSGi,则嵌入库是最常用的选项(据我所知),并且对于OSGi容器中的其他包无关紧要。

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

如果您使用的是未启用OSGi的库,您可以查看某些提供OSGi的地方,这些库包含这些库,例如。

Spring启用了OSGi - 您应该可以自己部署这些捆绑包。我还建议您查看Spring Dynamic Modulesdocumentation)。如果您构建了支持Spring的软件包,那么您也可以从已经使用这些软件包准备的OSGi容器开始。我使用FUSE ESB(免费(基于apache servicemix)OSGi容器(以及更多)获得商业支持,取得了很好的经验。

所以虽然我没有回答你的具体问题,但我分享了一些经验,并希望能帮助你。祝你好运!

答案 1 :(得分:2)

使用-X选项运行Maven,它将获得bundle插件以打印它认为依赖树的内容

[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-plugin忽略了这一点。

根据FELIX-954,它几​​乎要访问所有可选的依赖项。 我能提供的唯一建议是找到那些可选的工件,并确保Maven可以解决它们。

答案 2 :(得分:0)

maven-bundle-plugin的传递依赖关系管理中存在一个错误causes it to look up optional dependencies(其中一些可能不存在)。我怀疑这是当它试图拉入粗麻布时发生的事情。

我的第二个K. Claszen的想法是在springource或fusesource上查找你的bundle的版本,但是如果你找不到捆绑包,那么maven-bundle-plugin会提供bundleall goal (it's described in the goals section)。此目标将使bundle插件为应用程序的所有传递依赖项创建bundle。然后,您可以使用在springsource / fusesource中找不到的那些。一旦完成此操作,您就不需要将jar嵌入到捆绑包中,这也将使其可用于其他捆绑包。

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

相关问题