OH3.2 Eclipse IDE: Caused by: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory

Hi,

I migrated from OH3.1 to OH3.2 on Eclipse IDE. Maven resolution if fine but when I link the add-on via IDE (debug) or import to OH3.2 distro, Im getting the following error. It seems that my custom bundle is unable to load LoggerFactory class. Any idea on how to resolve this? I have included a pom.xml for your reference too. Thanks

08:23:22.788 [ERROR] [o.thecodecloud.internal.CloudService] - bundle org.openhab.io.thecodecloud:3.2.0.202208030015 (164)[org.openhab.io.thecodecloud.internal.CloudService(273)] : Error during instantiation of the implementation object

java.lang.reflect.InvocationTargetException: null

at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?]

at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:?]

at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?]

at java.lang.reflect.Constructor.newInstance(Constructor.java:490) ~[?:?]

at org.apache.felix.scr.impl.inject.internal.ComponentConstructorImpl.newInstance(ComponentConstructorImpl.java:316) ~[org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.manager.SingleComponentManager.createImplementationObject(SingleComponentManager.java:286) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.manager.SingleComponentManager.createComponent(SingleComponentManager.java:115) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.manager.SingleComponentManager.getService(SingleComponentManager.java:1000) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.manager.SingleComponentManager.getServiceInternal(SingleComponentManager.java:973) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.manager.SingleComponentManager.getService(SingleComponentManager.java:918) [org.apache.felix.scr-2.1.30.jar:?]

at org.eclipse.osgi.internal.serviceregistry.ServiceFactoryUse$1.run(ServiceFactoryUse.java:216) [org.eclipse.osgi-3.16.300.jar:?]

at java.security.AccessController.doPrivileged(Native Method) ~[?:?]

at org.eclipse.osgi.internal.serviceregistry.ServiceFactoryUse.factoryGetService(ServiceFactoryUse.java:213) [org.eclipse.osgi-3.16.300.jar:?]

at org.eclipse.osgi.internal.serviceregistry.ServiceFactoryUse.getService(ServiceFactoryUse.java:114) [org.eclipse.osgi-3.16.300.jar:?]

at org.eclipse.osgi.internal.serviceregistry.ServiceConsumer$2.getService(ServiceConsumer.java:48) [org.eclipse.osgi-3.16.300.jar:?]

at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.getService(ServiceRegistrationImpl.java:547) [org.eclipse.osgi-3.16.300.jar:?]

at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.getService(ServiceRegistry.java:533) [org.eclipse.osgi-3.16.300.jar:?]

at org.eclipse.osgi.internal.framework.BundleContextImpl.getService(BundleContextImpl.java:656) [org.eclipse.osgi-3.16.300.jar:?]

at org.apache.felix.scr.impl.manager.SingleRefPair.getServiceObject(SingleRefPair.java:88) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.inject.methods.BindMethod.getServiceObject(BindMethod.java:675) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.manager.DependencyManager.getServiceObject(DependencyManager.java:2556) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.manager.DependencyManager.doInvokeBindMethod(DependencyManager.java:2075) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.manager.DependencyManager.invokeBindMethod(DependencyManager.java:2058) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.manager.SingleComponentManager.invokeBindMethod(SingleComponentManager.java:443) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.manager.DependencyManager$MultipleDynamicCustomizer.addedService(DependencyManager.java:333) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.manager.DependencyManager$MultipleDynamicCustomizer.addedService(DependencyManager.java:301) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.manager.ServiceTracker$Tracked.customizerAdded(ServiceTracker.java:1200) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.manager.ServiceTracker$Tracked.customizerAdded(ServiceTracker.java:1121) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.manager.ServiceTracker$AbstractTracked.trackAdding(ServiceTracker.java:928) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.manager.ServiceTracker$AbstractTracked.track(ServiceTracker.java:864) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.manager.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:1152) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.BundleComponentActivator$ListenerInfo.serviceChanged(BundleComponentActivator.java:114) [org.apache.felix.scr-2.1.30.jar:?]

at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:120) [org.eclipse.osgi-3.16.300.jar:?]

at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:957) [org.eclipse.osgi-3.16.300.jar:?]

at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:234) [org.eclipse.osgi-3.16.300.jar:?]

at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:151) [org.eclipse.osgi-3.16.300.jar:?]

at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:936) [org.eclipse.osgi-3.16.300.jar:?]

at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:873) [org.eclipse.osgi-3.16.300.jar:?]

at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:141) [org.eclipse.osgi-3.16.300.jar:?]

at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:261) [org.eclipse.osgi-3.16.300.jar:?]

at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:496) [org.eclipse.osgi-3.16.300.jar:?]

at org.apache.felix.scr.impl.manager.AbstractComponentManager$3.register(AbstractComponentManager.java:929) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.manager.AbstractComponentManager$3.register(AbstractComponentManager.java:915) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.manager.RegistrationManager.changeRegistration(RegistrationManager.java:133) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.manager.AbstractComponentManager.registerService(AbstractComponentManager.java:984) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.manager.AbstractComponentManager.activateInternal(AbstractComponentManager.java:752) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.manager.AbstractComponentManager.enableInternal(AbstractComponentManager.java:674) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.manager.AbstractComponentManager.enable(AbstractComponentManager.java:437) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.manager.ConfigurableComponentHolder.enableComponents(ConfigurableComponentHolder.java:667) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.BundleComponentActivator.initialEnable(BundleComponentActivator.java:305) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.Activator.loadComponents(Activator.java:554) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.Activator.access$200(Activator.java:70) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.Activator$ScrExtension.start(Activator.java:421) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.AbstractExtender.createExtension(AbstractExtender.java:196) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.AbstractExtender.modifiedBundle(AbstractExtender.java:169) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.AbstractExtender.modifiedBundle(AbstractExtender.java:49) [org.apache.felix.scr-2.1.30.jar:?]

at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:488) [org.eclipse.osgi-3.16.300.jar:?]

at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:1) [org.eclipse.osgi-3.16.300.jar:?]

at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:232) [org.eclipse.osgi-3.16.300.jar:?]

at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:450) [org.eclipse.osgi-3.16.300.jar:?]

at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:945) [org.eclipse.osgi-3.16.300.jar:?]

at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:234) [org.eclipse.osgi-3.16.300.jar:?]

at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:151) [org.eclipse.osgi-3.16.300.jar:?]

at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEventPrivileged(EquinoxEventPublisher.java:232) [org.eclipse.osgi-3.16.300.jar:?]

at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:138) [org.eclipse.osgi-3.16.300.jar:?]

at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:130) [org.eclipse.osgi-3.16.300.jar:?]

at org.eclipse.osgi.internal.framework.EquinoxContainerAdaptor.publishModuleEvent(EquinoxContainerAdaptor.java:217) [org.eclipse.osgi-3.16.300.jar:?]

at org.eclipse.osgi.container.Module.publishEvent(Module.java:499) [org.eclipse.osgi-3.16.300.jar:?]

at org.eclipse.osgi.container.Module.start(Module.java:486) [org.eclipse.osgi-3.16.300.jar:?]

at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:445) [org.eclipse.osgi-3.16.300.jar:?]

at aQute.launcher.Launcher.start(Launcher.java:687) [biz.aQute.launcher-6.0.0.jar:?]

at aQute.launcher.Launcher.startBundles(Launcher.java:667) [biz.aQute.launcher-6.0.0.jar:?]

at aQute.launcher.Launcher.activate(Launcher.java:573) [biz.aQute.launcher-6.0.0.jar:?]

at aQute.launcher.Launcher.launch(Launcher.java:403) [biz.aQute.launcher-6.0.0.jar:?]

at aQute.launcher.Launcher.run(Launcher.java:185) [biz.aQute.launcher-6.0.0.jar:?]

at aQute.launcher.Launcher.main(Launcher.java:161) [biz.aQute.launcher-6.0.0.jar:?]

at aQute.launcher.pre.EmbeddedLauncher.executeWithRunPath(EmbeddedLauncher.java:170) [biz.aQute.launcher.pre.jar:?]

at aQute.launcher.pre.EmbeddedLauncher.findAndExecute(EmbeddedLauncher.java:135) [biz.aQute.launcher.pre.jar:?]

at aQute.launcher.pre.EmbeddedLauncher.main(EmbeddedLauncher.java:52) [biz.aQute.launcher.pre.jar:?]

Caused by: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory

at org.openhab.io.thecodecloud.internal.CloudService.<init>(CloudService.java:74) ~[?:?]

... 79 more

08:23:22.796 [WARN ] [e.model.rule.scoping.RulesClassCache] - bundle org.openhab.core.model.rule:3.2.0.202112191916 (144)[org.openhab.core.model.rule.scoping.RulesClassCache(175)] : Could not get service from ref {org.openhab.io.thecodecloud.internal.CloudService, org.openhab.core.events.EventSubscriber, org.openhab.core.model.script.engine.action.ActionService}={service.config.factory=false, service.id=407, service.bundleid=164, service.scope=bundle, service.config.category=io, service.pid=[org.openhab.thecodecloud, org.openhab.thecodecloud], service.config.label=TheCode Cloud, component.name=org.openhab.io.thecodecloud.internal.CloudService, service.config.description.uri=io:thecodecloud, component.id=273}

08:23:22.797 [WARN ] [e.model.rule.scoping.RulesClassCache] - bundle org.openhab.core.model.rule:3.2.0.202112191916 (144)[org.openhab.core.model.rule.scoping.RulesClassCache(175)] : DependencyManager : invokeBindMethod : Service not available from service registry for ServiceReference {org.openhab.io.thecodecloud.internal.CloudService, org.openhab.core.events.EventSubscriber, org.openhab.core.model.script.engine.action.ActionService}={service.config.factory=false, service.id=407, service.bundleid=164, service.scope=bundle, service.config.category=io, service.pid=[org.openhab.thecodecloud, org.openhab.thecodecloud], service.config.label=TheCode Cloud, component.name=org.openhab.io.thecodecloud.internal.CloudService, service.config.description.uri=io:thecodecloud, component.id=273} for reference ActionService

08:23:22.799 [ERROR] [o.thecodecloud.internal.CloudService] - bundle org.openhab.io.thecodecloud:3.2.0.202208030015 (164)[org.openhab.io.thecodecloud.internal.CloudService(273)] : Error during instantiation of the implementation object

java.lang.reflect.InvocationTargetException: null

at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?]

at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:?]

at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?]

at java.lang.reflect.Constructor.newInstance(Constructor.java:490) ~[?:?]

at org.apache.felix.scr.impl.inject.internal.ComponentConstructorImpl.newInstance(ComponentConstructorImpl.java:316) ~[org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.manager.SingleComponentManager.createImplementationObject(SingleComponentManager.java:286) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.manager.SingleComponentManager.createComponent(SingleComponentManager.java:115) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.manager.SingleComponentManager.getService(SingleComponentManager.java:1000) [org.apache.felix.scr-2.1.30.jar:?]

at org.apache.felix.scr.impl.manager.SingleComponentManager.getServiceInternal(SingleComponentManager.java:973) [org.apache.felix.scr-2.1.30.jar:?]

POM.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

4.0.0

org.openhab.addons.bundles org.openhab.addons.reactor.bundles 3.2.0-SNAPSHOT

org.openhab.io.mycloud

openHAB Add-ons :: Bundles :: IO :: My Cloud Connector

9.4.20.v20190813 !android.*, !com.android.*, !sun.* org.json json 20180813 compile org.apache.servicemix.bundles org.apache.servicemix.bundles.okhttp 3.8.1_1 compile org.apache.servicemix.bundles org.apache.servicemix.bundles.okio 1.13.0_1 compile
<dependency>
  <groupId>org.openhab.osgiify</groupId>
  <artifactId>io.socket.socket.io-client</artifactId>
  <version>1.0.1</version>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>org.openhab.osgiify</groupId>
  <artifactId>io.socket.engine.io-client</artifactId>
  <version>1.0.1</version>
  <scope>compile</scope>
</dependency>

<dependency>
  <groupId>org.eclipse.jetty.websocket</groupId>
  <artifactId>websocket-api</artifactId>
  <version>${jetty-version}</version>
  <scope>compile</scope>
</dependency>

<dependency>
  <groupId>org.eclipse.jetty.websocket</groupId>
  <artifactId>websocket-server</artifactId>
  <version>${jetty-version}</version>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>org.eclipse.jetty.websocket</groupId>
  <artifactId>websocket-servlet</artifactId>
  <version>${jetty-version}</version>
  <scope>compile</scope>
</dependency>

<dependency>
  <groupId>javax.websocket</groupId>
  <artifactId>javax.websocket-api</artifactId>
  <version>1.1</version>
  <scope>compile</scope>
</dependency>

@J-N-K I saw that you managed to fix a similar issue in another thread when providing a standalone jar file that can be put into the addons folder, could you share how you resolved this? I am hitting the same issue during the development of a new, high performance persistence service that could be a replacement for MapDB. Dropping it into the addon directory causes it to throw

Caused by: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory

I am failing to understand why though, as I copied the mapdb directory and it should just work…

If you point me to that thread I might remember :slight_smile:

Right here: [SOLVED] Update to SNAPSHOT #1597 (and later) partially failed (AllPlay(=SOLVED), AmazonDashButton(=SOLVED), wrapper service(=SOLVED), Z-Wave(=SOLVED)) - #43 by J-N-K

I can’t remember. But as a first step ypu could have a look at the generated MANIFEST.MF. Does it include org.slf4j in the Import-Package part?

There are 2 files:

./target/dependency/META-INF/MANIFEST.MF
./target/classes/META-INF/MANIFEST.MF

Neither one contains org.slf4j

That’s the problem. The question is: why.

You can use

<properties>
  <bnd.importpackage>org.slf4j.*</bnd.importpackage>
</properties>

as a temporary workaround. But something is wrong with the way the bundle is created.

That does not help (for whatever reason). It looks like this now:

  <properties>
    <bnd.importpackage>
      org.openhab.core.library.types,
      org.slf4j.*,
      !jdk.internal.misc
    </bnd.importpackage>
  </properties>

I can see that in history/dependencies.xml there is

<bundle>mvn:org.slf4j/slf4j-api/1.7.36</bundle>

I did a mvn clean and mvn install on the 4.2.0 branch and then copied the jar into my addons directory on the server which is running 4.2.0-1.

Can you show the code?

Sure, it is basically a copy of mapdb, just the backend was changed to chronicle: GitHub - Flole998/openhab-addons at chronicle4.2

  • You can’t distribute that over more than one line because it is passed directly to BND.
  • Why do you need to explictely import org.openhab.core.library.types?
  • SLF4J is now imported automatically, but with a wrong version range: [1.7,2) instead of [2.0,3). You might need to add an exclusion to the imported dependencies.
  • Feature resolution fails because it tries to resolve net.openhft.chronicle.algo. Either add it to the excluded packages in bnd.importpackage (if it is not needed) or add a dependency that provides this package.

I saw this in other addons IIRC.

Copied from mapdb.

Ah, so “something” is depending on it, so it ends up there but with the wrong version? That seems to be chronicle-core I think (I thought it provides chronicle.algo, I will have to double-check that).

Thanks, lets see if that helps!

It might work if you add proper BND line-endings. I would recommend to stay with one line.

IIRC it is needed there because otherwise de-serialization of the values fails. Check if you really need that (leave it in for now, when the whole add-on works, try if it continues to do so when you remove that import).

The 3rd party BOM from chronicle specifies SLF4J 1.7. Try to exclude it by adding

        <exclusions>
          <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
          </exclusion>
        </exclusions>

to the dependencies. Regarding chronicle.algo: It could be an optional dependency (i.e. not needed in some situations). If that is the case, you can exclude it in bnd.importpackage. If it is needed, you’ll see a ClassDefNotFoundException.

I have added more dependencies now, it builds fine but I am stuck at

Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.IllegalAccessError: class net.openhft.chronicle.core.OS (in unnamed module @0x2b372d03) cannot access class sun.nio.ch.FileChannelImpl (in module java.base) because module java.base does not export sun.nio.ch to unnamed module @0x2b372d03 [in thread "Refresh Thread: Equinox Container: cb47b8a1-f9e2-471c-82d0-9de10a950caf"]
        at net.openhft.chronicle.core.OS.<clinit>(OS.java:75) ~[?:?]
        ... 88 more

now. I can see that other bindings make use of sun.nio.ch, but for some reason I need to either ignore it (then I see the error from above) or building fails.

I don’t know. I spend an hour now getting that to work but it’s very difficult because of the large number of dependencies which are (partly) not OSGi ready. What exactly is the benefit of chronicle over mapdb? To me it looks like a very large solution.

I think the version I pushed last night has the dependencies correctly resolved, except for the
sun.nio one mentioned above.

The reason to look for MapDB alternatives is, that in my case openHAB spends 30% of it’s CPU time on MapDB stuff (mostly calling commit). Chronicle should have a significantly better performance, and I was expecting it to be lightweight (well, seems like that didn’t play out very well). I thought it would be easier than for example LMDB, which is also very very quick. I’ll try that one next, maybe it’s easier to include. It seems to have a lot less dependencies.