ClassNotFoundException: org.apache.felix.dm.DependencyActivatorBase with Pax Exam

I am using Pax Exam (3.5.0) for my OSGi unit tests. I have created a test but when I run it I get this stacktrace:

java.lang.NoClassDefFoundError: org/apache/felix/dm/DependencyActivatorBase
    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.Felix.createBundleActivator(Felix.java:4329)
    at org.apache.felix.framework.Felix.activateBundle(Felix.java:2141)
    at org.apache.felix.framework.Felix.startBundle(Felix.java:2064)
    at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1291)
    at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:304)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: org.apache.felix.dm.DependencyActivatorBase not found by com.company.wine.infrastructure [19]
    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)
    ... 14 more

I have configured CoreOptions.mavenBundle("org.apache.felix", "org.apache.felix.dependencymanager", "3.1.0") in the options and I see that org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.swissbox.extender.BundleWatcher] : Scanning bundle [org.apache.felix.dependencymanager] is loaded.

Still I get the exception. Anyone a clue on what I am doing wrong?

Cheers.

Answer

You have to differentiate in the way Pax Exam is designed and how you used it. Pax Exams main use case is to use it in an integration test where you test a previously build artifact. If you want to test it in the same module you have two ways of doing so.
1) in the Integrationtest-Phase of maven by referencing the freshly build artifact via a file: dependency.
2) by building a tiny-bundle containing your testable classes and other artifacts. This will need to also alter the Package-Imports/Exports in your test. A sample of doing this can be found here

Leave a Reply

Your email address will not be published. Required fields are marked *