简体   繁体   English

OSGI捆绑无法启动

[英]OSGI bundle is unable to start

I have an OSGI bundle which gets to the RESOLVED state, but never reaches the ACTIVE state. 我有一个OSGI包,它进入RESOLVED状态,但从未达到ACTIVE状态。 When I run my application, this is the stacktrace I am obtaining: http://tny.cz/fa949f16 当我运行我的应用程序时,这是我获得的堆栈跟踪: http//tny.cz/fa949f16

Afterwards, when I try to start the bundle explicitly through the OSGI console, I get this error: 之后,当我尝试通过OSGI控制台显式启动软件包时,我收到此错误:

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

Notice that in the end of the stacktrace ouput, there's the following message: 请注意,在stacktrace输出结束时,会出现以下消息:

!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. !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]未激活。

Here's the code from WinServiceActivator: 这是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;
    }
}

And this is my MANIFEST file: 这是我的MANIFEST文件:

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

While googling the error "Activator start error, ClassCastException: xxxx cannot be cast to org.osgi.framework.BundleActivator", I found this: 在搜索错误“Activator start error,ClassCastException:xxxx无法转换为org.osgi.framework.BundleActivator”时,我发现了这个:

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]

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: 根据这个评论我在互联网上找到了以下人员的评论和答案,我试图在MANIFEST文件中替换这一行:

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

by this one: 通过这个:

Import-Package: org.osgi.framework

And I get a whole bunch of errors in the code, whose reason given by Eclipse is: 我在代码中得到了一大堆错误,Eclipse的原因是:

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 此行的多个标记 - 访问限制:由于对所需库的限制,无法访问BundleActivator类型rsy.home.mac.sm.jaxrs.lib / lib / org.osgi.core-4.2.0.jar - 访问限制:由于对所需库rsy.home.mac.sm.jaxrs.lib / lib / org.osgi.core-4.2.0.jar的限制,无法访问BundleListener类型

I would really appreciate some help on this... Thanks! 我真的很感激这方面的帮助...谢谢!

I had a similar exception some time ago when I tried to get CXF working in an eclipse rcp application. 前段时间我尝试让CXF在eclipse rcp应用程序中工作时遇到了类似的异常。 The reason was that I did require bunddle on org.eclipse.osgi. 原因是我确实需要在org.eclipse.osgi上进行捆绑。 You should avoid that. 你应该避免这种情况。

Require bundle means that you import all packages of that bundle. 需要捆绑包意味着您导入该捆绑包的所有包。 The framework bundle (org.eclipse.osgi) exports the OSGi API. 框架包(org.eclipse.osgi)导出OSGi API。 Probably another bundle listed in your require bundle list also exports the BundleActivator package. 您的require bundle列表中列出的另一个bundle也可能导出BundleActivator包。 So you get the class from two sources and likely use a different one than the framework itself. 所以你从两个来源获得这个类,并且可能使用与框架本身不同的类。

These problems are the reqson why you should avoid require bundle. 这些问题是为什么你应该避免需要捆绑的问题。 Espcially try to avoid doing require bundle on org.eclipse.osgi. 特别是尽量避免在org.eclipse.osgi上执行require bundle。 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. 在我使用cxf的情况下,我遇到了与org.eclipse.osgi导出的jaxb api类似的问题,以及cxf带来的其中一个包。

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 http://njbartlett.name/2011/02/09/uses-constraints.html

In general if you have the chance use the maven bundle plugin or bndtools to generate the Manifest. 一般情况下,如果您有机会使用maven bundle插件或bndtools来生成Manifest。 Both have good defaults that avoid most of these problems. 两者都具有良好的默认值,可以避免大多数这些问题。

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

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