Simple OSGi application with dependencies inside bundle.
I am playing with karaf. I started by writing a simple rest application.
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. I added guava as an example and got an exception when installing the bundle in 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; osgi.identity=karaf-rest-core-blueprint; type=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<=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; osgi.identity=org.apache.karaf.examples.karaf-rest-core-blueprint; type=osgi.bundle; version="[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; 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.
:
<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.
question from:
https://stackoverflow.com/questions/65884569/simple-osgi-application-with-dependencies-inside-bundle 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…