为什么这个测试包失败了?

时间:2012-04-08 18:47:57

标签: java eclipse osgi

我正在尝试进行一个非常简单的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 个答案:

答案 0 :(得分:1)

你有没看过jar档案?它看起来像你在jar命令中缺少'test'文件夹 - 如果Activator.class在jar根目录而不是在正确的目录中,则类加载器将找不到它。