我是 OSGI 新手,正在尝试部署我的第一个应用程序。我的 pom.xml 中有一个 spring 依赖项。在部署时,我意识到 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没有所需版本的存储库。例如这个来自 hessian 3.1.3 等。
[INFO] Unable to find resource 'hessian:hessian:pom:3.1.3' in repository central
(http://repo1.maven.org/maven2)
如果有人可以分享他们在这方面的经验,我将不胜感激。
-谢谢
最佳答案
在 OSGi 环境中,部署所需库的常见方法是将它们部署为自己的包。如果库未启用 OSGi,则嵌入库是最常用的选项(据我所知),并且对于 OSGi 容器中的其他 bundle 无关紧要。
因此,如果您的 bundle 依赖于其他库,您应该首先查看这些库是否启用了 OSGi,并将它们作为自己的 bundle 安装在 OSGi 容器中。
如果您使用未启用 OSGi 的库,您可以查看一些提供启用 OSGi 的这些库的“包装”包的地方,例如
Spring 启用了 OSGi - 您应该可以自己部署这些包。我还建议看看Spring Dynamic Modules (documentation)。如果您构建支持 Spring 的 bundle ,您还可以从已经使用这些 bundle 准备好的 OSGi 容器开始。我通过FUSE ESB取得了很好的经验(这是免费的(基于 apache servicemix )OSGi 容器(以及更多)并具有商业支持)。
因此,虽然我没有回答您的具体问题,但我分享了一些我的经验,希望对您有所帮助。祝你好运!
关于osgi - Felix maven-bundle-plugin 传递依赖问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6303035/