gpt4 book ai didi

java - OSGI bundle 无法启动

转载 作者:行者123 更新时间:2023-12-02 06:04:33 24 4
gpt4 key购买 nike

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

之后,当我尝试通过 OSGI 控制台显式启动 bundle 时,出现以下错误:

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

请注意,在堆栈跟踪输出的末尾,有以下消息:

!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 的代码:

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

这是我的 list 文件:

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

在谷歌搜索错误“Activator启动错误,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.

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

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

您认为这就是 bundle 无法启动的原因吗?如果是这样,我该如何解决这个问题?根据我在互联网上找到的这条评论以及下面人们的评论和答案,我尝试替换 MANIFEST 文件中的这一行:

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

通过这个:

Import-Package: org.osgi.framework

我在代码中遇到了一大堆错误,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

我真的很感谢对此的一些帮助...谢谢!

最佳答案

不久前,当我尝试让 CXF 在 eclipse rcp 应用程序中工作时,我遇到了类似的异常。原因是我确实需要 org.eclipse.osgi 上的包。你应该避免这种情况。

需要 bundle 意味着您导入该 bundle 的所有包。框架包 (org.eclipse.osgi) 导出 OSGi API。也许您的需求包列表中列出的另一个包也导出 BundleActivator 包。因此,您从两个来源获取该类,并且可能使用与框架本身不同的来源。

这些问题是您应该避免 require 捆绑的原因。特别是尽量避免在 org.eclipse.osgi 上进行 require 捆绑。该 bundle 还导出系统导出中定义的所有包。因此它会导出大量包,并且您遇到问题的可能性很高。就我的 cxf 而言,我对 org.eclipse.osgi 以及 cxf 附带的 bundle 之一导出的 jaxb api 也有类似的问题。

本文可能会为您提供更多详细信息,因为您观察到的问题通常表现为违反使用约束。 http://njbartlett.name/2011/02/09/uses-constraints.html

一般来说,如果您有机会使用 Maven 捆绑插件或 bndtools 来生成 list 。两者都有很好的默认设置,可以避免大多数此类问题。

关于java - OSGI bundle 无法启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22406759/

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