在过去的一天半里,以下看似琐碎的问题使我发疯:
-捆绑包“ 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

最佳答案

(nb:我只是注意到在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进行索引。通过我的中央代理服务器获取的诗歌中;代理下载工件后,OBR repository.xml就会更新,并且捆绑包中的软件包可以通过OBR解析。

但是后来Netty发生了。 Their -sources.jar has complete Bundle headers matching that of their actual bundles进入OSGI框架后,它可以正确解析,所有标头(名称,版本,导出,导入)都与实际的包匹配,因此您无法告诉您已加载了正在导出.java文件

关于java - 对于OSGi运行时可用的类型的ClassNotFoundException(io.netty.common),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23149966/

10-14 10:37