简体   繁体   中英

Why does this test bundle fail?

I'm trying to make a very simple OSGi test but I can't get it to work. It seems like the OSGi runtime can't find my activator class. Any clues?

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

I compile and package my activator with

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

and run OSGi with

$ 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

Have you had a look inside the jar archive? It looks to me like you're missing the 'test' folder in the jar command - if the Activator.class is in the jar root instead of in the right directory, the classloader won't find it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM