[英]Simple OSGi application with dependencies inside bundle
Simple OSGi application with dependencies inside bundle.包含依赖项的简单 OSGi 应用程序。
I am playing with karaf.我在玩卡拉夫。 I started by writing a simple rest application.我首先编写了一个简单的 rest 应用程序。 https://github.com/YaroslavTir/osgi-jersey-hibertate/tree/stackoverflow/examples/karaf-rest-core https://github.com/YaroslavTir/osgi-jersey-hibertate/tree/stackoverflow/examples/karaf-rest-core
I took karaf examples as backbond and it was quite simple to run my first bundle with rest endpoints, but then I faced an issue when I added maven dependency.我将 karaf 示例作为 backbond,使用 rest 端点运行我的第一个包非常简单,但是当我添加 maven 依赖项时遇到了一个问题。 I added guava as an example and got an exception when installing the bundle in karaf我添加了番石榴作为示例,在 karaf 中安装捆绑包时出现异常
<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
Error executing command: Unable to resolve root: missing requirement [root] osgi.identity;执行命令时出错:无法解析 root:缺少要求 [root] osgi.identity; osgi.identity=karaf-rest-core-blueprint; osgi.identity=karaf-rest-core-blueprint; type=karaf.feature;类型=karaf.feature; version="[4.3.1.SNAPSHOT,4.3.1.SNAPSHOT]";版本="[4.3.1.SNAPSHOT,4.3.1.SNAPSHOT]"; filter:="(&(osgi.identity=karaf-rest-core-blueprint)(type=karaf.feature)(version>=4.3.1.SNAPSHOT)(version<=4.3.1.SNAPSHOT))" [caused by: Unable to resolve karaf-rest-core-blueprint/4.3.1.SNAPSHOT: missing requirement [karaf-rest-core-blueprint/4.3.1.SNAPSHOT] osgi.identity; filter:="(&(osgi.identity=karaf-rest-core-blueprint)(type=karaf.feature)(version>=4.3.1.SNAPSHOT)(version<=4.3.1.SNAPSHOT))" [导致作者:无法解决 karaf-rest-core-blueprint/4.3.1.SNAPSHOT:缺少要求 [karaf-rest-core-blueprint/4.3.1.SNAPSHOT] osgi.identity; osgi.identity=org.apache.karaf.examples.karaf-rest-core-blueprint; osgi.identity=org.apache.karaf.examples.karaf-rest-core-blueprint; type=osgi.bundle;类型=osgi.bundle; version="[4.3.1.SNAPSHOT,4.3.1.SNAPSHOT]";版本="[4.3.1.SNAPSHOT,4.3.1.SNAPSHOT]"; resolution:=mandatory [caused by: Unable to resolve org.apache.karaf.examples.karaf-rest-core-blueprint/4.3.1.SNAPSHOT: missing requirement [org.apache.karaf.examples.karaf-rest-core-blueprint/4.3.1.SNAPSHOT] osgi.wiring.package;分辨率:=强制[原因:无法解析 org.apache.karaf.examples.karaf-rest-core-blueprint/4.3.1.SNAPSHOT:缺少要求 [org.apache.karaf.examples.karaf-rest-core-core-蓝图/4.3.1.SNAPSHOT] osgi.wiring.package; filter:="(&(osgi.wiring.package=com.google.common.collect)(version>=29.0.0)(.(version>=30.0.0)))"]] filter:="(&(osgi.wiring.package=com.google.common.collect)(version>=29.0.0)(.(version>=30.0.0)))"]]
I read somewhere that org.apache.felix.maven-bundle-plugin has a bug and add optional dependency to the bundle, and this looks like true, as I can see in MANIFEST.MF/Import-Package dependncy like com.google.appengine.api that should not be there.我在某处读到 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>
I know that should be super simple, and I just miss some small but important detail.我知道这应该非常简单,我只是错过了一些小而重要的细节。
Your error means that your bundle karaf-rest-core-blueprint
has a dependency on com.google.common.collect
and this dependency can't be resolved in the container.您的错误意味着您的捆绑包karaf-rest-core-blueprint
依赖于com.google.common.collect
并且无法在容器中解决此依赖关系。
In other words, you did'nt install guava into Karaf.换句话说,您没有将 guava 安装到 Karaf 中。
$ bundle:install -s mvn:com.google.guava/failureaccess/1.0.1
$ bundle:install -s mvn:com.google.guava/guava-29.0-jre
In a real app, you should create a feature which installs all your dependencies/bundles.在一个真实的应用程序中,您应该创建一个安装所有依赖项/捆绑包的功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.