问题描述
简单的 Osgi 应用程序,在 bundle 中有依赖项。
我在玩卡拉夫。我首先编写了一个简单的休息应用程序。 https://github.com/YaroslavTir/osgi-jersey-hibertate/tree/stackoverflow/examples/karaf-rest-core
我将 karaf 示例作为backbond,运行我的第一个带有 rest 端点的包非常简单,但是当我添加 maven 依赖项时,我遇到了一个问题。我以番石榴为例,在karaf中安装bundle时出现异常
<dependencies>
...
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>29.0-jre</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.Felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
<Export-Package>org.apache.karaf.core.rest.blueprint</Export-Package>
<Import-Package>
*
</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
> git clone https://github.com/YaroslavTir/osgi-jersey-hibertate
> mvn clean install
> feature:repo-add mvn:org.apache.karaf.examples/karaf-rest-core-features/LATEST/xml
> feature:install karaf-rest-core-blueprint
错误执行命令:无法解析root:缺少需求[root] osgi.identity; osgi.identity=karaf-rest-core-blueprint;类型=karaf.feature; version="[4.3.1.SNAPSHOT,4.3.1.SNAPSHOT]"; filter:="(&(osgi.identity=karaf-rest-core-blueprint)(type=karaf.feature)(version>=4.3.1.SNAPSHOT)(version=29.0.0)(!(version>=30.0.0)))"]]
我在某处读到 org.apache.Felix.maven-bundle-plugin 有一个错误并向包添加了可选的依赖项,这看起来是真的,正如我在 MANIFEST.MF/Import-Package 中看到的 像 com.google.appengine.api 这样不应该存在的依赖项。 :
<dependencies>
...
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>29.0-jre</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.Felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
<Export-Package>org.apache.karaf.core.rest.blueprint</Export-Package>
<Embed-Dependency>*;scope=compile|runtime;inline=false</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Embed-Directory>target/dependency</Embed-Directory>
</instructions>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
我知道这应该非常简单,我只是错过了一些小而重要的细节。
解决方法
您的错误意味着您的包 karaf-rest-core-blueprint
依赖于 com.google.common.collect
,并且无法在容器中解析此依赖项。
换句话说,您没有将番石榴安装到 Karaf 中。
$ bundle:install -s mvn:com.google.guava/failureaccess/1.0.1
$ bundle:install -s mvn:com.google.guava/guava-29.0-jre
在实际应用中,您应该创建一个功能来安装所有依赖项/包。