I'm working with an OSGi BundleActivator code. When I'm trying to install it using Apache Karaf I always get a Unable to install bundle mvn:com.baeldung/osgi-intro-sample-activator/1.0-SNAPSHOT: org.osgi.framework.BundleException: Unable to cache bundle: mvn:com.baeldung/osgi-intro-sample-activator/1.0-SNAPSHOT
error.
The tutorial I tried to follow is here: https://www.baeldung.com/osgi
The command I use is bundle:install mvn:com.baeldung/osgi-intro-sample-activator/1.0-SNAPSHOT
. Tried to add -s flag or use install
instead of bundle:install
, didn't help. Tried to run it from the Karaf root and bundle directory, didn't help.
In a Karaf folder I tried to set org.ops4j.pax.url.mvn.localRepository=/Users/bogdansalyp/.m2/repository
, didn't help.
Emptied .m2/repository
, didn't help. Copied it to the bundle and Karaf folders, didn't help.
Tried mvn install
and mvn clean install
from different directories, didn't help.
Karaf is v4.2.6, maven is 3.1.1
Here's my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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>
<artifactId>osgi-intro-sample-activator</artifactId>
<name>osgi-intro-sample-activator</name>
<!-- Please, note this is not the usual 'jar'. -->
<packaging>bundle</packaging>
<!-- com.baeldung/osgi-intro-sample-activator/1.0-SNAPSHOT -->
<parent>
<artifactId>osgi</artifactId>
<groupId>com.baeldung</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.artifactId}</Bundle-Name>
<Bundle-Version>${project.version}</Bundle-Version>
<!-- Qualified name of the class that exposes the activator iface. -->
<Bundle-Activator>com.baeldung.osgi.sample.activator.HelloWorld</Bundle-Activator>
<!-- One important thing to note: since you are not exporting the package "com.baeldung.osgi.sample.activator", you should at least add it to the Private-Package
instruction. Otherwise, the classes inside the package will not be copied to your bundle, as the default value of this instruction is empty. -->
<Private-Package>com.baeldung.osgi.sample.activator</Private-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
Here's the Java code I use:
package com.baeldung.osgi.sample.activator;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class HelloWorld implements BundleActivator {
public void start(BundleContext ctx) {
System.out.println("Hello World.");
}
public void stop(BundleContext bundleContext) {
System.out.println("Goodbye World.");
}
}
The code structure can be found here: https://github.com/eugenp/tutorials/tree/master/osgi/osgi-intro-sample-activator
Thanks in advance for your help!