0

在过去的一天半里,以下看似微不足道的问题一直让我发疯: - 捆绑包“netty-worker-service”导出了一个简单的接口,该接口包含由 io.netty.transport 提供(导出)的类型

package com.github.andlaz.netty.worker.service.api;

import io.netty.channel.nio.NioEventLoopGroup;

 public interface NettyWorkerService {

   public NioEventLoopGroup getWorkerGroup();

 }

它还实现了这个接口并将其声明为服务:

package com.github.andlaz.netty.worker.service.impl;

import io.netty.channel.nio.NioEventLoopGroup;
import aQute.bnd.annotation.component.Component;

import com.github.andlaz.netty.worker.service.api.NettyWorkerService;

@Component(immediate=true)
public class NettyWorkerServiceImpl implements NettyWorkerService {

    private final NioEventLoopGroup workerGroup = new NioEventLoopGroup();

    @Override
    public NioEventLoopGroup getWorkerGroup() {
        return workerGroup;
    }

}

bnd 创建以下组件 xml

<component name="com.github.andlaz.netty.worker.service.impl.NettyWorkerServiceImpl" immediate="true">
  <implementation class="com.github.andlaz.netty.worker.service.impl.NettyWorkerServiceImpl"/>
  <service>
    <provide interface="com.github.andlaz.netty.worker.service.api.NettyWorkerService"/>
  </service>
</component>

manifest.mf

Manifest-Version: 1.0
Bnd-LastModified: 1397806521471
Bundle-ManifestVersion: 2
Bundle-Name: com.github.andlaz.netty.worker.service
Bundle-SymbolicName: netty-worker-service
Bundle-Version: 1.0.0
Created-By: 1.7.0_45 (Oracle Corporation)
Export-Package: com.github.andlaz.netty.worker.service.api;version="1.0"
 ;uses:="io.netty.channel.nio"
Import-Package: com.github.andlaz.netty.worker.service.api;version="[1.0
 ,2)",io.netty.channel.nio;version="[4.0,5)"
Private-Package: com.github.andlaz.netty.worker.service.impl
Service-Component: OSGI-INF/com.github.andlaz.netty.worker.service.impl.
 NettyWorkerServiceImpl.xml
Tool: Bnd-2.2.0.20130927-173417

不是太复杂的东西,对吧?但是,使用以下bndrun配置:

-runfw: org.apache.felix.framework;version='[4,5)'
-runee: JavaSE-1.7
-runsystemcapabilities: ${native_capability}

-resolve.effective: active

-runbundles: io.netty.buffer;version='[4.0.18,4.0.19)',\
    io.netty.common;version='[4.0.15,4.0.16)',\
    io.netty.transport;version='[4.0.15,4.0.16)',\
    netty-worker-service;version=latest,\
    org.apache.felix.configadmin;version='[1.6.0,1.6.1)',\
    org.apache.felix.gogo.command;version='[0.12.0,0.12.1)',\
    org.apache.felix.gogo.runtime;version='[0.10.0,0.10.1)',\
    org.apache.felix.gogo.shell;version='[0.10.0,0.10.1)',\
    org.apache.felix.log;version='[1.0.1,1.0.2)',\
    org.apache.felix.scr;version='[1.8.2,1.8.3)',\
    osgi.enterprise;version='[4.2.0,4.2.1)'

-runrequires: osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.shell)',\
    osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.command)',\
    osgi.identity;filter:='(&(osgi.identity=netty-worker-service)(version>=1.0.0))',\
    osgi.identity;filter:='(&(osgi.identity=org.apache.felix.log)(version>=1.0.1))'

虽然一切都正确解决,但我在日志中看到以下内容..

014.04.18 09:35:31 INFO - Bundle: org.apache.felix.framework - [java.lang.Object, aQute.launcher.Launcher] - ServiceEvent REGISTERED
2014.04.18 09:35:31 INFO - Bundle: osgi.enterprise - BundleEvent STARTED
2014.04.18 09:35:31 INFO - Bundle: org.apache.felix.scr - BundleEvent STARTED
2014.04.18 09:35:31 INFO - Bundle: org.apache.felix.scr - [org.apache.felix.scr.impl.ScrGogoCommand] - ServiceEvent REGISTERED
2014.04.18 09:35:31 ERROR - Bundle: netty-worker-service - [com.github.andlaz.netty.worker.service.impl.NettyWorkerServiceImpl(0)] Failed creating the component instance; see log for reason
2014.04.18 09:35:31 ERROR - Bundle: netty-worker-service - [com.github.andlaz.netty.worker.service.impl.NettyWorkerServiceImpl(0)] Error during instantiation of the implementation object - org.apache.felix.log.LogException: java.lang.NoClassDefFoundError: io/netty/util/concurrent/EventExecutorGroup
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.findClass(BundleWiringImpl.java:2279)
    at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1501)
    at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.findClass(BundleWiringImpl.java:2279)
    at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1501)
    at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.findClass(BundleWiringImpl.java:2279)
    at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1501)
    at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at org.apache.felix.framework.BundleWiringImpl.getClassByDelegation(BundleWiringImpl.java:1374)
    at org.apache.felix.framework.BundleWiringImpl.searchImports(BundleWiringImpl.java:1553)
    at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1484)
    at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at com.github.andlaz.netty.worker.service.impl.NettyWorkerServiceImpl.<init>(NettyWorkerServiceImpl.java:11)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at java.lang.Class.newInstance(Class.java:374)
    at org.apache.felix.scr.impl.manager.SingleComponentManager.createImplementationObject(SingleComponentManager.java:253)
    at org.apache.felix.scr.impl.manager.SingleComponentManager.createComponent(SingleComponentManager.java:127)
    at org.apache.felix.scr.impl.manager.SingleComponentManager.getService(SingleComponentManager.java:871)
    at org.apache.felix.scr.impl.manager.SingleComponentManager.getServiceInternal(SingleComponentManager.java:838)
    at org.apache.felix.scr.impl.manager.AbstractComponentManager.activateInternal(AbstractComponentManager.java:850)
    at org.apache.felix.scr.impl.manager.AbstractComponentManager.enable(AbstractComponentManager.java:419)
    at org.apache.felix.scr.impl.config.ConfigurableComponentHolder.enableComponents(ConfigurableComponentHolder.java:376)
    at org.apache.felix.scr.impl.BundleComponentActivator.initialize(BundleComponentActivator.java:172)
    at org.apache.felix.scr.impl.BundleComponentActivator.<init>(BundleComponentActivator.java:120)
    at org.apache.felix.scr.impl.Activator.loadComponents(Activator.java:258)
    at org.apache.felix.scr.impl.Activator.access$000(Activator.java:45)
    at org.apache.felix.scr.impl.Activator$ScrExtension.start(Activator.java:185)
    at org.apache.felix.utils.extender.AbstractExtender.createExtension(AbstractExtender.java:259)
    at org.apache.felix.utils.extender.AbstractExtender.modifiedBundle(AbstractExtender.java:232)
    at org.apache.felix.utils.extender.AbstractExtender.addingBundle(AbstractExtender.java:192)
    at org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(BundleTracker.java:467)
    at org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(BundleTracker.java:414)
    at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)
    at org.osgi.util.tracker.AbstractTracked.trackInitial(AbstractTracked.java:183)
    at org.osgi.util.tracker.BundleTracker.open(BundleTracker.java:156)
    at org.apache.felix.utils.extender.AbstractExtender.startTracking(AbstractExtender.java:150)
    at org.apache.felix.utils.extender.AbstractExtender.doStart(AbstractExtender.java:142)
    at org.apache.felix.scr.impl.Activator.doStart(Activator.java:117)
    at org.apache.felix.utils.extender.AbstractExtender.start(AbstractExtender.java:114)
    at org.apache.felix.scr.impl.Activator.start(Activator.java:92)
    at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:645)
    at org.apache.felix.framework.Felix.activateBundle(Felix.java:2146)
    at org.apache.felix.framework.Felix.startBundle(Felix.java:2064)
    at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)
    at aQute.launcher.Launcher.update(Launcher.java:378)
    at aQute.launcher.Launcher.activate(Launcher.java:303)
    at aQute.launcher.Launcher.run(Launcher.java:193)
    at aQute.launcher.Launcher.main(Launcher.java:89)
Caused by: java.lang.ClassNotFoundException: io.netty.util.concurrent.EventExecutorGroup not found by io.netty.common [2]
    at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1532)
    at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at org.apache.felix.framework.BundleWiringImpl.getClassByDelegation(BundleWiringImpl.java:1374)
    at org.apache.felix.framework.BundleWiringImpl.searchImports(BundleWiringImpl.java:1553)
    at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1484)
    at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 66 more

2014.04.18 09:35:31 INFO - Bundle: netty-worker-service - [com.github.andlaz.netty.worker.service.api.NettyWorkerService] - ServiceEvent REGISTERED
2014.04.18 09:35:31 INFO - Bundle: org.apache.felix.scr - [org.osgi.service.cm.ManagedService] - ServiceEvent REGISTERED
2014.04.18 09:35:31 INFO - Bundle: org.apache.felix.scr - [org.apache.felix.scr.ScrService] - ServiceEvent REGISTERED
2014.04.18 09:35:31 INFO - Bundle: org.apache.felix.scr - [org.osgi.service.cm.ConfigurationListener] - ServiceEvent REGISTERED
2014.04.18 09:35:31 INFO - Bundle: org.apache.felix.log - BundleEvent STARTED
2014.04.18 09:35:31 INFO - Bundle: org.apache.felix.log - [org.osgi.service.log.LogReaderService] - ServiceEvent REGISTERED
2014.04.18 09:35:31 INFO - Bundle: org.apache.felix.log - [org.osgi.service.log.LogService] - ServiceEvent REGISTERED
g! 

tl;dr:io.netty.util.concurrent.EventExecutorGroup 无处可寻。

Caused by: java.lang.ClassNotFoundException: io.netty.util.concurrent.EventExecutorGroup not found by io.netty.common [2]

我验证了以下内容: - io.netty.transport 从 io.netty.common 正确导入此类型 - io.netty.common 包含并导出此类型

我不知道如何继续调试。任何指针都非常感谢!项目源代码可在https://github.com/andlaz/netty-worker-service获得

4

1 回答 1

1

(注:我刚刚注意到在 runbundles 中混合了小版本的 netty 包,将所有版本设置为 [4.0.15,4.0.16) 没有区别 - 但是:)-

使用 netty 4.0.18 我无法再重现这个 - 一切都完美无缺。

-runbundles: io.netty.buffer;version='[4.0.18,5)',\
    io.netty.common;version='[4.0.18,5)',\
    io.netty.transport;version='[4.0.18,5)',\

我将不得不检查 .15 和 .18 之间的更改,但更新似乎已经修复了导致此问题的任何原因。

我终于想通了。一点背景故事:

我使用 Nexus 创建 Maven Central 的 .m2 代理存储库,这让我的依赖项的安全性不会消失在空气中(不是那个 Central 一直在这样做)。

然而,最重要的是,我有一个 OBR 代理(代理的代理 :-)),它从我的 Central 代理中缓存的任何内容中过滤掉 Bundles,并在 repository.xml 中为 bundles 编制索引完美地工作 - 我<type>bundle</type>在我的 poms 中添加了依赖项通过我的中央代理获取的;一旦代理下载了工件,OBR repository.xml 就会更新,并且包中的包可以通过 OBR 解析。

但后来Netty发生了。他们的 -sources.jar 具有与其实际捆绑包匹配的完整捆绑包标头当它进入 OSGI 框架时,它被正确解析,所有标头(名称、版本、导出、导入)都与实际捆绑包匹配,因此有你没有办法告诉你加载了一个正在导出 .java 文件的包

于 2014-04-18T10:17:34.233 回答