OSGi Containers

Each OSGi test container is able to launch an OSGi framework and to provision bundles into the running framework.

Native Container

The Native Container runs in the same VM as the driver. This is the recommended approach for most cases.

Project dependencies for native container
<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>3.4.0</exam.version>
        <url.version>1.6.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

The Forked Container uses the OSGi Framework Launch API to launch the framework in a separate VM. It provides maximum isolation and avoids classloader issues that may arise with the Native Container. The price you have pay for this is slower start-up and remote debugging. The forked container uses RMI to communicate between the jvm the started the test and the separate vm that runs the framework.

Project dependencies for forked container
<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>3.0.0</exam.version>
        <url.version>1.5.2</url.version>
    </properties>

    <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>

</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>