Почему при запуске службы отображается сообщение "Активатор не найден"?

Я написал тестовый класс для тестирования OSGi Felix Framework. Класс выглядит следующим образом:

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]

Почему я получаю эту ошибку? пожалуйста посоветуй.

1 ответ

Решение

Я думаю, что проблема в том, что ваши классы неправильно упакованы в вашем файле JAR. Файл MANIFEST настроен корректно, и вы используете правильный параметр в команде jar, чтобы добавить его в свой файл jar.

Я рекомендую вам использовать более продвинутую систему сборки для сборки вашего проекта, например, Ant или Maven. Вот образец build.xml файл для Ant. Возможно, вы можете попробовать с ним, чтобы увидеть, если это решит вашу проблему.

<project name="My project" default="package" basedir=".">
    <description>My project</description>
    <property name="bin.dir" location="bin"/>
    <property name="src.dir" location="src"/>
    <property name="libs.dir" location="(the folder where my jar are)"/>

    <path id="src">
        <pathelement location="${src.dir}"/>
    </path>

    <target name="compile">
        <mkdir dir="${bin.dir}"/>
        <mkdir dir="${bin.dir}/META-INF"/>
        <javac srcdir="${src.dir}" destdir="${bin.dir}" debug="true" debuglevel="lines,vars,source" source="1.7"  target="1.7">
            <classpath>
                <fileset dir="${libs.dir}">
                    <include name="**/*.jar" />
                </fileset>
            </classpath>
        </javac>
        <copy todir="${bin.dir}/META-INF">
            <fileset dir="${src.dir}/META-INF"/>
        </copy>
    </target>

    <target name="package" depends="compile">
        <mkdir dir="${basedir}/target"/>
        <delete file="${basedir}/target/myjarfile.jar" />
        <zip destfile="${basedir}/target/myjarfile.jar"
             basedir="${bin.dir}"/>
    </target>
</project>

Надеюсь, это поможет тебе, Тьерри

Другие вопросы по тегам