2

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

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

-谢谢

4

3 回答 3

3

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

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

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

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

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

于 2011-06-10T07:39:54.410 回答
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 可以解决它们。

于 2012-05-30T04:18:19.273 回答
0

maven-bundle-plugin 的传递依赖项管理中存在一个错误,导致它查找可选依赖​​项(其中一些可能不存在)。我怀疑这就是它试图拉入粗麻布时发生的事情。

我会支持 K. Claszen 在 springsource 或 fusesource 上寻找你的 bundle 版本的想法,但是如果你找不到 bundle,maven-bundle-plugin 提供了一个bundleall 目标(在目标部分中有描述)。这个目标将导致 bundle 插件为你的应用程序的所有传递依赖创建 bundle。然后,您可以使用在 springsource/fusesource 中找不到的那些。完成此操作后,您无需将 jar 嵌入到您的包中,这将使它们也可用于其他包。

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

于 2011-06-22T01:46:11.700 回答