Question

I am using the latest Pax Exam (3.3.0) for OSGi testing. I have Pax Exam up and running, deploying and starting my bundles etc. Life is good.

I also have a utility project containing various factories and other helpful functionality that I want to be able to re-use in multiple test projects. It is a maven project which is included as a dependency ion the Pax Exam pom.xml.

However, as soon as I try to access any of the classes contained within the utility jar I get a ClassNotFoundException. I've been playing around with the class loader and discovered that I can directly load the class via a URLClassLoader. But still, I get the ClassNotFoundException thrown.

Turning the utility project into a bundle is not an option. I will need to use the utility code in @BeforeClass annotated methods and the BundleContext instance hasn't been injected yet.

Can anybody tell me the best/easiest way to get my utility project inside Pax Exam?

Was it helpful?

Solution

As pointed out in the official documentation, @BeforeClass is not supported by Pax Exam, at least not in the expected way. It is executed by the JUnit driver and not inside the test container, that's why there is no bundle context.

If you want your code to be run in the container, it has to be in a bundle.

This question has been discussed here.

OTHER TIPS

You can simply take the utility jar and add it as a wrapped bundle. Then it will be loaded into your OSGI container. You just need to define the exported packages you will need.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top