2012-04-08 77 views
1

我试图做一个非常简单的OSGi测试,但我无法得到它的工作。看起来OSGi运行时无法找到我的激活器类。任何线索?这个测试包为什么会失败?

Activator.java:

package test; 

import org.osgi.framework.BundleActivator; 
import org.osgi.framework.BundleContext; 

public class Activator implements BundleActivator 
{ 
    public void start(BundleContext context) throws Exception 
    { 
     System.out.println("Hello world"); 
    } 


    public void stop(BundleContext context) throws Exception 
    { 
     System.out.println("Goodbye World"); 
    } 
} 

MANIFEST.MF

Manifest-Version: 1.0 
Bundle-Name: Test 
Bundle-SymbolicName: Test 
Bundle-Version: 1.0.0 
Bundle-Activator: test.Activator 
Import-Package: org.osgi.framework 

我编译和打包我的激活与

$ javac -classpath /usr/share/java/org.eclipse.osgi.jar Activator.java 
$ jar cmf MANIFEST.MF test.jar Activator.class 

与运行的OSGi

$ java -jar /usr/share/java/org.eclipse.osgi.jar -console 

$ osgi> install file:///home/august/Documents/prog/java/osgi/test/test.jar 
Bundle id is 1 
$ osgi> start 1 
org.osgi.framework.BundleException: The activator test.Activator for bundle Test is invalid 
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:171) 
... 
at java.lang.Thread.run(Thread.java:679) 
Caused by: java.lang.ClassNotFoundException: test.Activator 

回答

1

你有看过jar包吗?在我看来,你错过了jar命令中的'test'文件夹 - 如果Activator.class位于jar根目录而不是正确的目录中,那么classloader将无法找到它。

+0

啊,当然。谢谢! – 2012-04-08 19:07:11