我为 OSGi Felix 框架测试编写了一个测试类。课程如下:
package tutorial.example2.service;
import java.util.Hashtable;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class Activator implements BundleActivator {
@Override
public void start(BundleContext context) throws Exception {
Hashtable<String, String> props = new Hashtable<String, String>();
props.put("Language", "English");
context.registerService(DictionaryService.class.getName(),
new DictionaryImpl(), props);
}
@Override
public void stop(BundleContext context) throws Exception {
// TODO Auto-generated method stub
}
private static class DictionaryImpl implements DictionaryService {
String[] m_dictionary = { "welcome", "to", "the", "osgi", "tutorial" };
public boolean checkWord(String word) {
word = word.toLowerCase();
for (int i = 0; i < m_dictionary.length; i++) {
if (m_dictionary[i].equals(word)) {
return true;
}
}
return false;
}
}
}
以下是我的 manifest.mf 文件:
Bundle-Name: English dictionary
Bundle-Description: A bundle that registers an English dictionary service
Bundle-Vendor: Apache Felix
Bundle-Version: 1.0.0
Bundle-Activator: tutorial.example2.service.Activator
Export-Package: tutorial.example2.service
Import-Package: org.osgi.framework
然后我使用以下 2 个命令编译类并生成捆绑 jar 文件。
javac -cp C:\Users\user\Desktop\felix-framework-4.0.3\bin\felix.jar *.java service\*.java
jar cfm producer.jar manifest_producer.mf -C C:\Users\kavin\Desktop \assignment2\producer
然后我登录到 OSGi,当我使用以下命令启动服务时,
start file:/C:/Users/user/Desktop/assignment2/producer.jar
它给出了一个 BundleException:Not Found 激活器类。例外情况如下:
g! start file:/C:/Users/mayooranM/Desktop/TESTWS/Example2/src/tutorial/example2/
服务/example.jar
org.osgi.framework.BundleException: Not found: tutorial.example2.service.Activat
or
at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:417
5)
at org.apache.felix.framework.Felix.activateBundle(Felix.java:1972)
at org.apache.felix.framework.Felix.startBundle(Felix.java:1895)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:944)
at org.apache.felix.gogo.command.Basic.start(Basic.java:729)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.felix.gogo.runtime.Reflective.invoke(Reflective.java:137)
at org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:
82)
at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:477)
at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:4
03)
at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:183)
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:120)
at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessi
onImpl.java:89)
at org.apache.felix.gogo.shell.Console.run(Console.java:62)
at org.apache.felix.gogo.shell.Shell.console(Shell.java:203)
at org.apache.felix.gogo.shell.Shell.gosh(Shell.java:128)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.felix.gogo.runtime.Reflective.invoke(Reflective.java:137)
at org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:
82)
at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:477)
at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:4
03)
at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:183)
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:120)
at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessi
onImpl.java:89)
at org.apache.felix.gogo.shell.Activator.run(Activator.java:75)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: tutorial.example2.service.Activator
not found by [95]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDele
gation(BundleWiringImpl.java:1460)
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringIm
pl.java:72)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadCla
ss(BundleWiringImpl.java:1843)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.apache.felix.framework.BundleWiringImpl.getClassByDelegation(Bund
leWiringImpl.java:1317)
at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:417
0)
... 33 more
java.lang.ClassNotFoundException: tutorial.example2.service.Activator not found
由 [95]
为什么我会收到这个错误?请指教。