我在apache Karaf 3.0.3中创建一个简单的Echo服务包,我有我的Activator类,
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;
}
我可以使用以下Mannifest文件
创建Bundle Via eclipseManifest-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"
我还有以下POM文件
<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>
也是我的Echo Class
package com.company.echo;
public class Echo {
public String echo(final String string) {
return string;
}
}
当我在karaf 3.0.3上部署此应用程序时,我遇到以下问题
尝试启动软件包时获取以下堆栈跟踪
错误:Bundle com.company.osgi [112]启动/停止bundle时出错。 (org.osgi.framework.BundleException:bundle com.company.osgi中的未解决约束[112]:无法解析112.0:缺少需求[112.0] osgi.wiring.package;(&amp;(osgi.wiring.package = org。 osgi.framework)(版本&GT; = 1.8.0))) org.osgi.framework.BundleException:bundle com.company.osgi中的未解析约束[112]:无法解析112.0:缺少需求[112.0] osgi.wiring.package; (及(osgi.wiring.package = org.osgi.framework)(版本&GT; = 1.8.0)) 在org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3974) 在org.apache.felix.framework.Felix.startBundle(Felix.java:2037) 在org.apache.felix.framework.Felix.setBundleStartLevel(Felix.java:1483) 在org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:334) 在java.lang.Thread.run(Thread.java:745)
有些人可以帮我弄清楚确切的问题是什么。
提前致谢..!
答案 0 :(得分:1)
我不认为karaf 3支持OSGi Core R6(org.osgi.framework包版本1.8)。您应该尝试针对其他版本的OSGi API进行编译。