简体   繁体   English

找不到OSGI激活器类

[英]OSGI Activator class not found

I'm trying to make the simplest OSGI example in order to see if it works on a particular Java Virtual Machine. 我正在尝试制作最简单的OSGI示例,以查看它是否可在特定的Java虚拟机上运行。 Currently I'm testing it with Open JDK 1.8.0. 目前,我正在使用Open JDK 1.8.0对其进行测试。

I'm following this tutorial. 我正在关注教程。 I have the exact same files except that I removed the package statement from the .java file and also from the manifest (I just want to make it simpler). 我有完全相同的文件,除了我从.java文件和清单中删除了package语句(我只是想使其更简单)。

So basically the manifest looks like that: 所以清单基本上是这样的:

Bundle-Name: Service listener example
Bundle-Description: A bundle that displays messages at startup and when service events occur
Bundle-Vendor: Apache Felix
Bundle-Version: 1.0.0
Bundle-Activator: Activator
Import-Package: org.osgi.framework

I am able to generate the jar file. 我能够生成jar文件。 It's contents is the following: 其内容如下:

" zip.vim version v27
" Browsing zipfile /home/cosmin/OSGI_Testing/osgi/test.jar
" Select a file with cursor and press ENTER

META-INF/
META-INF/MANIFEST.MF
build/Activator.class

I run the Apache Felix, I install the .jar file and when I start it throws that exception: 我运行Apache Felix,安装.jar文件,然后在启动时抛出该异常:

ERROR: Bundle [1] Error starting file:/home/cosmin/OSGI_Testing/osgi/. /test.jar (org.osgi.framework.BundleException: Not found: Activator)
java.lang.ClassNotFoundException: Activator not found by [1]
  at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1610)
  at org.apache.felix.framework.BundleWiringImpl.access$200(BundleWiringImpl.java:80)
  at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2018)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
  at org.apache.felix.framework.BundleWiringImpl.getClassByDelegation(BundleWiringImpl.java:1404)
  at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:4505)
  at org.apache.felix.framework.Felix.activateBundle(Felix.java:2220)
  at org.apache.felix.framework.Felix.startBundle(Felix.java:2145)
  at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1372)
  at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:308)

What is the problem? 问题是什么?

Thank you respectfully. 谢谢你。

There are several problems in this. 这有几个问题。 The Activator class is in the wrong folder ... but that was already mentioned. Activator类位于错误的文件夹中……但这已被提及。 Apart from this you should always use a package name in OSGi. 除此之外,您应该始终在OSGi中使用程序包名称。 Especially later when you want to share packages you have to make sure that the same package is not used in more than one jar. 尤其是在以后要共享软件包时,必须确保多个罐中不使用同一软件包。

You seem to create the Manifest by hand. 您似乎是手动创建清单。 This is a very error prone process. 这是一个非常容易出错的过程。 I recommend to use a maven build and use either the maven-bundle-plugin or the bnd-maven-plugin to generate the Manifest. 我建议使用maven构建,并使用maven-bundle-plugin或bnd-maven-plugin生成清单。 This is a lot safer. 这样更安全。

You can look into a tutorial I did some time ago . 您可以查看我前一段时间做的教程 Maybe you need to strip it down for your case but you will see the maven build. 也许您需要根据情况进行精简,但是您会看到Maven的构建。

Starting with an Activator for your first try is a good idea .. but you should then quickly switch to a dependency injection framework. 从Activator开始进行第一次尝试是一个好主意..但是您应该随后迅速切换到依赖项注入框架。 For OSGi I recommend to look into declarative services. 对于OSGi,我建议研究声明式服务。

I think the Activator-class should not be in the build-folder. 我认为Activator类不应该在构建文件夹中。 Remove the build-folder. 删除构建文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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