gpt4 book ai didi

java - 为什么我在启动服务时收到 "Activator not found"?

转载 作者:行者123 更新时间:2023-12-01 11:43:22 25 4
gpt4 key购买 nike

我为 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]

为什么我会收到这个错误?请指教。

最佳答案

我认为问题在于您的类未正确打包在 JAR 文件中。 MANIFEST 文件已正确配置,并且您在 jar 命令中使用正确的选项将其添加到您的 jar 文件中。

我建议您使用更高级的构建系统来构建您的项目,例如 Ant 或 Maven。以下是 Ant 的示例 build.xml 文件。也许您可以尝试一下,看看它是否可以解决您的问题。

<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>

希望对你有帮助蒂埃里

关于java - 为什么我在启动服务时收到 "Activator not found"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29328932/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com