I am creating a simple Echo service bundle in apache Karaf 3.0.3, I have my Activator class,
package com.company.activator;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class Activator implements BundleActivator {
private static BundleContext context;
static BundleContext getContext() {
return context;
}
/*
* (non-Javadoc)
*
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
public void start(final BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
}
/*
* (non-Javadoc)
*
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
public void stop(final BundleContext bundleContext) throws Exception {
Activator.context = null;
}
I am able to create the Bundle Via eclipse, with the following Mannifest file
Manifest-Version: 1.0
Private-Package: com.company.activator
Built-By: noushad
Tool: Bnd-0.0.238
Bundle-Name: osgi
Created-By: Apache Maven Bundle Plugin
Build-Jdk: 1.7.0_76
Bundle-Version: 1.0.0
Bnd-LastModified: 1427119505629
Bundle-ManifestVersion: 2
Bundle-Activator: com.company.activator.Activator
Export-Packages: com.company.echo
Bundle-SymbolicName: com.company.osgi
Import-Package: org.osgi.framework;version="1.8"
Also I have the following POM file
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company</groupId>
<artifactId>osgi</artifactId>
<packaging>bundle</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>osgi Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>6.0.0</version>
</dependency>
</dependencies>
<build>
<finalName>osgi</finalName>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>1.4.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${pom.groupId}.${pom.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${pom.artifactId}</Bundle-Name>
<Bundle-Version>1.0.0</Bundle-Version>
<Private-Package>com.company.activator</Private-Package>
<Bundle-Activator>com.company.activator.Activator</Bundle-Activator>
<Export-Packages>com.company.echo</Export-Packages>
<Import-Package>*</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
Also my Echo Class
package com.company.echo;
public class Echo {
public String echo(final String string) {
return string;
}
}
I face the following problem(s) when i deploy this application on the karaf 3.0.3
Getting the following stack trace when I try to start the bundle
ERROR: Bundle com.company.osgi [112] Error starting/stopping bundle. (org.osgi.framework.BundleException: Unresolved constraint in bundle com.company.osgi [112]: Unable to resolve 112.0: missing requirement [112.0] osgi.wiring.package; (&(osgi.wiring.package=org.osgi.framework)(version>=1.8.0))) org.osgi.framework.BundleException: Unresolved constraint in bundle com.company.osgi [112]: Unable to resolve 112.0: missing requirement [112.0] osgi.wiring.package; (&(osgi.wiring.package=org.osgi.framework)(version>=1.8.0)) at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3974) at org.apache.felix.framework.Felix.startBundle(Felix.java:2037) at org.apache.felix.framework.Felix.setBundleStartLevel(Felix.java:1483) at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:334) at java.lang.Thread.run(Thread.java:745)
Could Some body help me to figure out what the exact problem is.
Thanks in advance..!
I don't think karaf 3 supports OSGi Core R6 (org.osgi.framework package version 1.8). You should try compiling against an other version of the OSGi API.