Another important aspect of application development is automated build. This permits application artifacts to be created outside of the developer’s IDE. The application can then be created and tested in a variety of environments, including continuous integration servers.
All of the GreenPages projects have Maven POM files for building.
The PAR is built using the file pom.xml
in the greenpages
folder.
This file defines a parent POM and a packaging type of par
:
<parent> <groupId>org.eclipse.virgo</groupId> <artifactId>greenpages.parent</artifactId> <version>2.4.0.RELEASE</version> <relativePath>../greenpages.parent</relativePath> </parent> <modelVersion>4.0.0</modelVersion> <groupId>org.eclipse.virgo</groupId> <artifactId>greenpages</artifactId> <name>GreenPages PAR</name> <description>GreenPages PAR</description> <packaging>par</packaging>
Thorsten Maus created a Maven plugin (see Section A.2, “Documentation”)
that builds a PAR file from a list of dependencies.
The file pom.xml
lists those dependencies:
<dependencies> <dependency> <groupId>org.eclipse.virgo</groupId> <artifactId>greenpages.app</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>org.eclipse.virgo</groupId> <artifactId>greenpages.jpa</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>org.eclipse.virgo</groupId> <artifactId>greenpages.db</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>org.eclipse.virgo</groupId> <artifactId>greenpages.web</artifactId> <version>${project.version}</version> <type>war</type> </dependency> <dependency> <groupId>org.freemarker</groupId> <artifactId>com.springsource.freemarker</artifactId> <scope>provided</scope> </dependency> </dependencies>
The freemarker dependency is required to ensure the Web Application Bundle has the correct set of dependencies.
Most dependencies are resolved
transitively from the bundle projects, but the ‘war’ project does not pass on its dependencies;
it expects
them to be contained in its lib
directory.
The <build><plugins>…
section contains a declaration for the
par
plugin and configuration of the application symbolic name of the PAR:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-par-plugin</artifactId> <version>1.0.0.RELEASE</version> <configuration> <applicationSymbolicName>greenpages</applicationSymbolicName> </configuration> </plugin>
The Maven dependency
plugin is used to collect the transitive dependency graph for the PAR.
The <build><plugins>…
section
has a declaration for the dependency
plugin:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/par-provided</outputDirectory> <overWriteIfNewer>true</overWriteIfNewer> <excludeGroupIds>org.eclipse.virgo,org.apache.log4j</excludeGroupIds> </configuration> </execution> </executions> </plugin>
The WAB must be prevented from having its dependencies included in a lib
directory as they should be provided
by the runtime enviroment. The greenpages.web
POM file contains the following:
<build> <plugins> <plugin> <artifactId>maven-war-plugin</artifactId> <version>2.1-beta-1</version> <configuration> <packagingExcludes>WEB-INF/lib/**</packagingExcludes> </configuration> </plugin> </plugins> </build>
The following plug-in entry in the pom.xml
file in the parent
directory ensure that the concrete test classes are run as part of the build:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <includes> <include>**/*Tests.java</include> </includes> <excludes> <exclude>**/Abstract*.java</exclude> </excludes> <junitArtifactName>org.junit:com.springsource.org.junit</junitArtifactName> <argLine>-javaagent:${user.home}/.m2/repository/…</argLine> </configuration> </plugin>
The location of the user's Maven repository is hard-coded.