0

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.

Tuno
  • 1,234
  • 1
  • 13
  • 22
  • 1
    Do you have the import for it in your bundle? Is this test a integration test or do you use it as a unit test? – Achim Nierbeck Jun 25 '14 at 04:53
  • I use it as a unit test. Import package in my bundle did the trick for the unit test. However I don't understand why it works when I deploy it to Felix without this import. – Tuno Jun 25 '14 at 07:17

1 Answers1

0

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

Achim Nierbeck
  • 5,265
  • 2
  • 14
  • 22