【问题标题】:Felix maven-bundle-plugin transitive dependency issueFelix maven-bundle-plugin 传递依赖问题
【发布时间】:2011-09-12 06:44:46
【问题描述】:

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

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


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

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

-谢谢

【问题讨论】:

    标签: osgi maven-plugin apache-felix


    【解决方案1】:

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

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

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

    Spring 支持 OSGi - 您应该可以自行部署这些包。我还建议看看Spring Dynamic Modules (documentation)。如果您构建启用 Spring 的包,您还可以从已经准备好这些包的 OSGi 容器开始。我对FUSE ESB(它是免费的(基于apache servicemix)OSGi 容器(以及更多)具有商业支持)取得了很好的体验。

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

    【讨论】:

    • @Claszen ..感谢您的回复。我正在使用 fuse esb 作为测试我的应用程序的工具。根据您的 cmets,我有几个后续问题。您提到安装OSGI 直接启用捆绑包而不是嵌入它们。这是否意味着您从 Spring DM 存储库手动复制 spring bundle(org.springframework.spring-library) 并使用命令行/felix 管理工具将其安装在 Fuse 中?它如何解决传递依赖?例如spring 内部会依赖 hibernate jars。是否意味着你也需要手动安装 hibernate 包?
    • @Sahamik 我将我的捆绑包聚合到功能以将它们安装在一起。查看 FUSE ESB 的 deploy 文档的功能章节。无法自动安装传递依赖项 - 您必须自己处理它们。 Feature 不是 OSGi 标准 - 其他容器可能会提供其他机制,使您能够一次安装一组捆绑包。 Spring 应该是 FUSE ESB 设置的一部分 - hibernate 还没有为 OSGi 准备好(据我所知) - 你会在 Internet 上找到在 OSGI 中启用 hibernate 的提示。
    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

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

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-01-25
        • 2011-05-20
        • 2010-11-08
        • 2021-06-20
        • 2013-01-12
        • 2011-05-21
        • 2020-06-14
        • 1970-01-01
        相关资源
        最近更新 更多