OSGI软件包无法启动 [英] OSGI bundle is unable to start

查看:178
本文介绍了OSGI软件包无法启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个OSGI包,它到达了RESOLVED状态,但从来没有达到ACTIVE状态。当我运行我的应用程序时,这是我获取的堆栈跟踪: http://tny.cz/fa949f16

I have an OSGI bundle which gets to the RESOLVED state, but never reaches the ACTIVE state. When I run my application, this is the stacktrace I am obtaining: http://tny.cz/fa949f16

之后,当我尝试通过OSGI控制台显式启动捆绑包时,我收到这个错误:

Afterwards, when I try to start the bundle explicitly through the OSGI console, I get this error:

start 53
gogo: BundleException: The activator rsy.home.mac.sm.schedule.service.win.WinServiceActivator for bundle rsy.home.mac.sm.schedule.service.win is invalid

请注意,在stacktrace输出结束时,出现以下消息:

Notice that in the end of the stacktrace ouput, there's the following message:


!ENTRY org.eclipse.osgi 4 0 2014-03-14 10:52:50.984!MESSAGE Bundle
rsy.home.mac.sm .schedule.service.win_1.0.0 [53]不活动。

!ENTRY org.eclipse.osgi 4 0 2014-03-14 10:52:50.984 !MESSAGE Bundle rsy.home.mac.sm.schedule.service.win_1.0.0 [53] is not active.

这是WinServiceActivator中的代码:

Here's the code from WinServiceActivator:

package rsy.home.mac.sm.schedule.service.win;

import java.util.HashMap;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleListener;


public class WinServiceActivator implements BundleActivator {

    private static BundleContext context;

    @Override
    public void start(BundleContext context) throws Exception {

        ServiceActivator.context = context;

        ScheduleService schedServ = new ScheduleService();

        schedServ.setTdMapping(new HashMap<String, String>());
        schedServ.setHtMapping(new HashMap<String, String>());
        schedServ.setDoMapping(new HashMap<String, String>());

        context.registerService(ScheduleService.class.getName(), 
                schedServ, null);
    }

    @Override
    public void stop(BundleContext context) throws Exception {

        context.ungetService(context.getServiceReference(ScheduleService.class.getName()));
        ServiceActivator.context = null;
    }
}

这是我的更新文件:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: SM Schedule Query Service
Bundle-SymbolicName: rsy.home.mac.sm.schedule.service.sm;singleton:=true
Bundle-Version: 1.0.0
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Service-Component: OSGI-INF/sm_schedule_service.xml
Require-Bundle: rsy.home.mac.sm.jaxrs.lib;bundle-version="1.0.0",
 rsy.home.mac.sm.config;bundle-version="0.1.0",
 rsy.home.mac.log,
 rsy.home.mac.sm.model;bundle-version="1.0.0",
 rsy.home.mac.sm.schedule.service;bundle-version="1.0.0",
 rsy.home.mac.sm.sm.scheduletable;bundle-version="1.0.0",
 resources;bundle-version="1.0.0",
 rsy.home.mac.portal.utilities,
 rsy.home.mac.portal.logging;bundle-version="1.0.0",
 org.eclipse.xsd;bundle-version="2.7.0",
 org.eclipse.osgi
Import-Package: org.osgi.service.http;version="1.2.1"
Bundle-ActivationPolicy: lazy
Bundle-Activator: rsy.home.mac.sm.schedule.service.sm.SmServiceActivator
Export-Package: rsy.home.mac.sm.schedule.service.sm

当googling错误Activator启动错误,ClassCastException: xxxx不能转换到org.osgi.framework.BundleActivator,我发现这个:

While googling the error "Activator start error, ClassCastException: xxxx cannot be cast to org.osgi.framework.BundleActivator", I found this:

That error is telling you that you have two copies of the BundleActivator class loaded into your VM somehow. The framework is using one and your bundle is using another.

Do you have any other bundles exporting org.osgi.framework? Where is your bundle getting this package from? If you issue the following command in the Felix shell you can see the wiring:

inspect package requirement <bundle-id>

or shortened to:

inspect p r <bundle-id>

Where <bundle-id> is the ID of your bundle, then you should see from where it is getting org.osgi.framework. If it is not the system bundle (org.apache.felix.framework), then you have an issue.

当我执行给定的命令时,我获得了这个输出:

When I executed the given command, I obtained this output:

org.osgi.framework; version="1.7.0" -> org.eclipse.osgi_3.9.0.v20130410-1557 [0]

你认为这是什么原因为什么bundle不启动?如果是这样,我该如何解决?按照我在互联网上发现的评论以及下面的人的评论和答案,我试图在MANIFEST文件中替换这一行:

Do you think this is the reason why the bundle doesn't start? If so, how can I fix this? Following this comment I found on the internet and the comments and answers from people below, I tried to replace this line in the MANIFEST file:

Import-Package: org.osgi.service.http;version="1.2.1"

通过这一个:

Import-Package: org.osgi.framework

我在代码中收到了一大堆错误,由Eclipse给出的原因是:

And I get a whole bunch of errors in the code, whose reason given by Eclipse is:


此行上的多个标记
- 访问限制:由于限制所需库
rsy.home.mac.sm.jaxrs.lib / lib / org.osgi.core-4.2.0.jar
- 访问限制:由于对所需库
rsy.home.mac.sm.jaxrs.lib / lib / org的限制,不能访问BundleListener类型.osgi.core-4.2.0.jar

Multiple markers at this line - Access restriction: The type BundleActivator is not accessible due to restriction on required library rsy.home.mac.sm.jaxrs.lib/lib/org.osgi.core-4.2.0.jar - Access restriction: The type BundleListener is not accessible due to restriction on required library rsy.home.mac.sm.jaxrs.lib/lib/org.osgi.core-4.2.0.jar

我真的很感激一些帮助,谢谢!

I would really appreciate some help on this... Thanks!

推荐答案

之前,当我试图让CXF在eclipse rcp应用程序中工作时,我有一个类似的异常。原因是我确实需要在org.eclipse.osgi上打包。你应该避免这种情况。

I had a similar exception some time ago when I tried to get CXF working in an eclipse rcp application. The reason was that I did require bunddle on org.eclipse.osgi. You should avoid that.

需要包意味着您导入该包的所有包。框架包(org.eclipse.osgi)导出OSGi API。可能在您的需求捆绑列表中列出的另一个捆绑包也会导出BundleActivator包。所以你从两个来源获得这个类,可能使用与框架本身不同的一个。

Require bundle means that you import all packages of that bundle. The framework bundle (org.eclipse.osgi) exports the OSGi API. Probably another bundle listed in your require bundle list also exports the BundleActivator package. So you get the class from two sources and likely use a different one than the framework itself.

这些问题是reqson为什么你应该避免需要捆绑。特意尝试避免在org.eclipse.osgi上执行require bundle。该bundle还会导出系统导出中定义的所有包。所以它出口大量的包,机会很高你遇到问题。在cxf的情况下,我有一个与org.eclipse.osgi导出的jaxb api以及cxf带来的其中一个bundle相似的问题。

These problems are the reqson why you should avoid require bundle. Espcially try to avoid doing require bundle on org.eclipse.osgi. THis bundle also exports all packages defined in the system exports. So it exports lots of packages and chances are high you run into problems. In my case with cxf I had a similar problem with the jaxb api that is exported by org.eclipse.osgi and also by one of the bundles cxf brings with it.

本文可能会给您一些更多的细节,因为您观察到的常见问题是使用约束违规。 http://njbartlett.name/2011/02/09/uses-constraints.html

This article may give you some more details as the problem you observe often surfaces as a uses constraint violation. http://njbartlett.name/2011/02/09/uses-constraints.html

一般来说,如果您有机会使用maven bundle插件或bndtools来生成清单。两者都有很好的默认值,可以避免大多数这些问题。

In general if you have the chance use the maven bundle plugin or bndtools to generate the Manifest. Both have good defaults that avoid most of these problems.

这篇关于OSGI软件包无法启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆