WAR Probe Assembly

Automatic Defaults

By default, Pax Exam automatically builds a WAR probe for Java EE and Web Containers from the class path and the web resource directory of the current project.

  • The class path defined by system property java.class.path is split into individual paths (referencing directories or archives).
  • A set of default classpath filters is applied to each of these paths: a path is dropped if it matches any of the given regular expressions. (See WarProbeOption.DEFAULT_CLASS_PATH_EXCLUDES.)
  • A WAR is built from the remaining paths. Each archive path is copied to WEB-INF/lib. Each directory path is recursively copied to WEB-INF/classes. The default web resource directory src/main/webapp (if existing) is recursively copied to the WAR root.

Manually Assembling a WAR Probe

Using a custom probe builder method and a warProbe() option with additional arguments, you can assemble the WAR probe from scratch or customize the automatic assembly by including a probe builder method in your test class:

import static org.ops4j.pax.exam.CoreOptions.options;
import static org.ops4j.pax.exam.CoreOptions.warProbe;

@Configuration
public Option[] config() {
    return options(warProbe());
}

The above minimal example creates an almost empty WAR containing nothing but an empty WEB-INF/beans.xml marker file. This empty file is added by default when no other WEB-INF/beans.xml resource is specified explicitly. The WAR can be filled by adding further arguments to the warProbe() options, e.g.

warProbe()
   .classes(Foo.class, Bar.class)
   .library("target/classes")
   .library(maven("junit", "junit", "4.11"))
   .overlay("WebResources/")

warProbe() Arguments

autoClasspath

  • Adds classes and resources from the classpath into the WAR.

    autoClasspath(true)   // takes classpath and applies default filters
    autoClasspath(false)  // takes classpath without applying default filters
    

classes

  • Adds classes to WEB-INF/lib.

    classes(Vanilla.class, Chocolate.class)
    

classPathDefaultExcludes

  • Adds classes and resources from the classpath into the WAR, applying the default filters. Equivalent to autoClassPath(true).

    classPathDefaultExcludes()
    

exclude

  • Applies additional classpath filters. A directory or archive from the classpath will be excluded if any of the given regular expressions matches a substring of the path element.

    exclude("myfaces", "jersey", "weld")
    

library

  • Adds the library from the given path to the WAR. If the path is a directory, it is assumed to be a class folder, and its contents are copied recursively to WEB-INF/classes.
    Otherwise, the path is assumed to be a JAR, and its contents are copied to WEB-INF/lib.

    library("lib/mylib.jar") // relative path
    library(maven("junit", "junit", "4.11")) // Maven GAV coordinates
    

metaInfResource

  • Adds the given resource from the class path to the WAR in META-INF/.

    metaInfResource("foo.properties") // copies /foo.properties to META-INF/foo.properties
    

name

  • Sets the base name of the generated WAR. If unset, a random name will be generated.

    name("test") // WAR probe file is named test.war
    

overlay

  • Adds an overlay from the given path to the WAR. This is similar to the overlay concept of the Maven WAR Plugin. If the overlay path is a directory, its contents are copied recursively to the root of the WAR. If the overlay path is an archive, its exploded contents are copied to the root of the WAR. An UrlReference option may be used to download an overlay archive from the given URL. All overlays are copied in the given order. All overlay are copied before any libraries, classes or resources.
overlay("web/") // recursively copy overlay from the given directory
overlay(maven("com.acme", "foo", "1.0").type("war")) // use a Maven WAR artifact as overlay

resources

Adds the given resources from the current class path to the WAR in WEB-INF/classes.

resources("com/acme/Messages.properties", "com/acme/Messages_de.properties")

webInfResource

  • Adds the given resource from the class path to the WAR in WEB-INF/.

    webInfResource("/beans.xml) // copies /beans.xml to WEB-INF/beans.xml