Pax Exam Maven Dependencies

Project Configuration

To work with Pax Exam in your project, you need to include a couple of Pax Exam and third-party libraries.

While Pax Exam does not require Maven, it works best in combination with Maven, and if you do not use Maven or any other build tool able to automatically pull dependencies from Maven repositories, your life will be a lot harder.

Due to the number of different test containers and OSGi frameworks supported by Pax Exam, there is no one-size-fits-all dependency snippet you can copy and paste into your POM.

The following are representative examples, one for each Pax Exam test container.

OSGi Containers

Native Container Example

With the Native Container, Pax Exam uses the OSGi FrameworkFactory API to look up an OSGi framework for running the tests. The Native Container launches the OSGi framework in the same VM.

Here is a self-contained example POM:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.ops4j.pax.exam</groupId>
    <artifactId>pax-exam-sample-empty</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <exam.version>2.5.0</exam.version>
        <url.version>1.4.0</url.version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.ops4j.pax.exam</groupId>
            <artifactId>pax-exam-container-native</artifactId>
            <version>${exam.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.ops4j.pax.exam</groupId>
            <artifactId>pax-exam-junit4</artifactId>
            <version>${exam.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.ops4j.pax.exam</groupId>
            <artifactId>pax-exam-link-mvn</artifactId>
            <version>${exam.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.ops4j.pax.url</groupId>
            <artifactId>pax-url-aether</artifactId>
            <version>${url.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.felix</groupId>
            <artifactId>org.apache.felix.framework</artifactId>
            <version>3.2.2</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>0.9.20</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>0.9.20</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

pax-exam-junit4 specifies the driver to be used for your tests. The JUnit driver is recommended, but you can also work with the TestNG driver or the Pax Exam Player.

The pax-url-aether dependency is required to resolve mvn: URLs and to provision Maven bundles.

org.apache.felix.framework is just one example of an OSGi framework. Of course, you can equally use an Equinox or Knopflerfish dependency.

Pax Exam, like most OPS4J projects, uses the SLF4J Logging API, which requires a logging backend, e.g. logback. See the SLF4J documentation for more details about alternative backends.

Forked Container Example

The Forked Container (since Pax Exam 2.4.0) forks a process running another Java VM which then uses the OSGi FrameworkFactory API to launch an OSGi framework for running the tests. The two Java processes communicate via RMI.

This set-up requires the following dependencies:

<dependency>
    <groupId>org.ops4j.pax.exam</groupId>
    <artifactId>pax-exam-container-forked</artifactId>
    <version>${exam.version}</version>
    <scope>test</scope>
</dependency>

<dependency>
    <groupId>org.ops4j.pax.exam</groupId>
    <artifactId>pax-exam-junit4</artifactId>
    <version>${exam.version}</version>
    <scope>test</scope>
</dependency>

<dependency>
    <groupId>org.ops4j.pax.exam</groupId>
    <artifactId>pax-exam-link-mvn</artifactId>
    <version>${exam.version}</version>
    <scope>test</scope>
</dependency>

<dependency>
    <groupId>org.ops4j.pax.url</groupId>
    <artifactId>pax-url-aether</artifactId>
    <version>${url.version}</version>
    <scope>test</scope>
</dependency>
 
<dependency>
    <groupId>org.apache.felix</groupId>
    <artifactId>org.apache.felix.framework</artifactId>
    <version>4.0.2</version>
    <scope>test</scope>
</dependency>

<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-core</artifactId>
    <version>0.9.29</version>
    <scope>test</scope>
</dependency>

<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>0.9.29</version>
    <scope>test</scope>
</dependency>


pax-exam-container-forked provides the Forked Container. See the Native Container example for more information about the other dependencies.

Pax Runner Container Example

Using Pax Exam with the Pax Runner container, Pax Exam's test driver will invoke the Pax Runner Java API. Pax Runner then launches an OSGi framework in a separate VM. Pax Exam and the remote OSGi framework communicate via RMI.

For this set-up, you need the following dependencies:

<dependency>
    <groupId>org.ops4j.pax.exam</groupId>
    <artifactId>pax-exam-container-paxrunner</artifactId>
    <version>${exam.version}</version>
    <scope>test</scope>
</dependency>

<dependency>
    <groupId>org.ops4j.pax.runner</groupId>
    <artifactId>pax-runner-no-jcl</artifactId>
    <version>${runner.version}</version>
    <scope>test</scope>
</dependency>

<dependency>
    <groupId>org.ops4j.pax.exam</groupId>
    <artifactId>pax-exam-junit4</artifactId>
    <version>${exam.version}</version>
    <scope>test</scope>
</dependency>

<dependency>
    <groupId>org.ops4j.pax.exam</groupId>
    <artifactId>pax-exam-link-mvn</artifactId>
    <version>${exam.version}</version>
    <scope>test</scope>
</dependency>

<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-core</artifactId>
    <version>0.9.29</version>
    <scope>test</scope>
</dependency>

<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>0.9.29</version>
    <scope>test</scope>
</dependency>

Pax Exam 2, like most current Pax projects, works with the SLF4J logging facade, this is why it uses pax-runner-no-jcl (without Apache Commons Logging aka JCL, which is used by plain pax-runner).

pax-exam-junit4 provides the optional JUnitTestRunner for Pax Exam.

Finally, pax-exam-link-mvn is just a collection of resources providing links to the Maven artifacts to be provisioned to the test container. These artifact links will be resolved by Pax Runner.

In contrast to the other two examples, pax-url-aether is not required in this case, as it is embedded in Pax Runner.