blob: 00ba9986605e905d70962bf69e9c0e7905da0ae5 [file] [log] [blame]
<html><head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Automated Build Highlights</title><meta content="DocBook XSL Stylesheets V1.76.0" name="generator"><link rel="home" href="index.html" title="A Guide to the GreenPages Sample"><link rel="up" href="ch03.html" title="Chapter&nbsp;3.&nbsp;GreenPages Highlights"><link rel="prev" href="ch03s03.html" title="Testing Highlights"><link rel="next" href="apa.html" title="Appendix&nbsp;A.&nbsp;Further Resources"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table summary="Navigation header" width="100%"><tr><td align="left" width="20%"><a accesskey="p" href="ch03s03.html">Prev</a>&nbsp;</td><th align="center" width="60%">&nbsp;</th><td align="right" width="20%">&nbsp;<a accesskey="n" href="apa.html">Next</a></td></tr></table><hr></div><div class="section" title="Automated Build Highlights"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="highlights.automated.build"></a>Automated Build Highlights</h2></div></div></div><p>
Another important aspect of application development is automated build. This permits
application artifacts to be created outside of the developer&rsquo;s IDE. The application can then be
created and tested in a variety of environments, including continuous integration servers.
</p><div class="section" title="Building the PAR"><div class="titlepage"><div><div><h3 class="title"><a name="N10642"></a>Building the PAR</h3></div></div></div><p>
All of the GreenPages projects have Maven POM files for building.
The PAR is built using the file <code class="filename">pom.xml</code> in the <code class="literal">greenpages</code> folder.
This file defines a parent POM and a packaging type of <code class="literal">par</code>:
</p><pre class="programlisting">&lt;parent&gt;
&lt;groupId&gt;org.eclipse.virgo&lt;/groupId&gt;
&lt;artifactId&gt;greenpages.parent&lt;/artifactId&gt;
&lt;version&gt;2.4.0.RELEASE&lt;/version&gt;
&lt;relativePath&gt;../greenpages.parent&lt;/relativePath&gt;
&lt;/parent&gt;
&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
&lt;groupId&gt;org.eclipse.virgo&lt;/groupId&gt;
&lt;artifactId&gt;greenpages&lt;/artifactId&gt;
&lt;name&gt;GreenPages PAR&lt;/name&gt;
&lt;description&gt;GreenPages PAR&lt;/description&gt;
&lt;packaging&gt;par&lt;/packaging&gt;
</pre><p>
</p><p>
Thorsten Maus created a Maven plugin (see <a class="xref" href="apas02.html" title="Documentation">Documentation</a>)
that builds a PAR file from a list of dependencies.
The file <code class="filename">pom.xml</code> lists those dependencies:
</p><pre class="programlisting">&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.eclipse.virgo&lt;/groupId&gt;
&lt;artifactId&gt;greenpages.app&lt;/artifactId&gt;
&lt;version&gt;${project.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.eclipse.virgo&lt;/groupId&gt;
&lt;artifactId&gt;greenpages.jpa&lt;/artifactId&gt;
&lt;version&gt;${project.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.eclipse.virgo&lt;/groupId&gt;
&lt;artifactId&gt;greenpages.db&lt;/artifactId&gt;
&lt;version&gt;${project.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.eclipse.virgo&lt;/groupId&gt;
&lt;artifactId&gt;greenpages.web&lt;/artifactId&gt;
&lt;version&gt;${project.version}&lt;/version&gt;
&lt;type&gt;war&lt;/type&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.freemarker&lt;/groupId&gt;
&lt;artifactId&gt;com.springsource.freemarker&lt;/artifactId&gt;
&lt;scope&gt;provided&lt;/scope&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
</pre><p>
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 &lsquo;war&rsquo; project does not pass on its dependencies;
it expects
them to be contained in its <code class="literal">lib</code> directory.
</p><p>
The <code class="literal">&lt;build&gt;&lt;plugins&gt;???</code> section contains a declaration for the
<code class="literal">par</code> plugin and configuration of the application symbolic name of the PAR:
</p><pre class="programlisting">&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-par-plugin&lt;/artifactId&gt;
&lt;version&gt;1.0.0.RELEASE&lt;/version&gt;
&lt;configuration&gt;
&lt;applicationSymbolicName&gt;greenpages&lt;/applicationSymbolicName&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
</pre><p>
</p></div><div class="section" title="Obtaining Dependencies"><div class="titlepage"><div><div><h3 class="title"><a name="N10679"></a>Obtaining Dependencies</h3></div></div></div><p>
The Maven <code class="literal">dependency</code> plugin is used to collect the transitive dependency graph for the PAR.
</p><p>
The <code class="literal">&lt;build&gt;&lt;plugins&gt;???</code> section
has a declaration for the <code class="literal">dependency</code> plugin:
</p><pre class="programlisting">&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;id&gt;copy-dependencies&lt;/id&gt;
&lt;phase&gt;package&lt;/phase&gt;
&lt;goals&gt;
&lt;goal&gt;copy-dependencies&lt;/goal&gt;
&lt;/goals&gt;
&lt;configuration&gt;
&lt;outputDirectory&gt;${project.build.directory}/par-provided&lt;/outputDirectory&gt;
&lt;overWriteIfNewer&gt;true&lt;/overWriteIfNewer&gt;
&lt;excludeGroupIds&gt;org.eclipse.virgo,org.apache.log4j&lt;/excludeGroupIds&gt;
&lt;/configuration&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;
</pre><p>
</p><p>
The WAB must be prevented from having its dependencies included in a <code class="literal">lib</code> directory as they should be provided
by the runtime enviroment. The <code class="literal">greenpages.web</code> POM file contains the following:
</p><pre class="programlisting">&lt;build&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
&lt;version&gt;2.1-beta-1&lt;/version&gt;
&lt;configuration&gt;
&lt;packagingExcludes&gt;WEB-INF/lib/**&lt;/packagingExcludes&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;</pre><p>
</p></div><div class="section" title="Automatically Running the Tests"><div class="titlepage"><div><div><h3 class="title"><a name="N106A0"></a>Automatically Running the Tests</h3></div></div></div><p>
The following plug-in entry in the <code class="literal">pom.xml</code> file in the <code class="literal">parent</code>
directory ensure that the concrete test classes are run as part of the build:
</p><pre class="programlisting">&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
&lt;configuration&gt;
&lt;includes&gt;
&lt;include&gt;**/*Tests.java&lt;/include&gt;
&lt;/includes&gt;
&lt;excludes&gt;
&lt;exclude&gt;**/Abstract*.java&lt;/exclude&gt;
&lt;/excludes&gt;
&lt;junitArtifactName&gt;org.junit:com.springsource.org.junit&lt;/junitArtifactName&gt;
&lt;argLine&gt;-javaagent:${user.home}/.m2/repository/???&lt;/argLine&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
</pre><p>
The location of the user's Maven repository is hard-coded.
</p></div></div><div class="navfooter"><hr><table summary="Navigation footer" width="100%"><tr><td align="left" width="40%"><a accesskey="p" href="ch03s03.html">Prev</a>&nbsp;</td><td align="center" width="20%"><a accesskey="u" href="ch03.html">Up</a></td><td align="right" width="40%">&nbsp;<a accesskey="n" href="apa.html">Next</a></td></tr><tr><td valign="top" align="left" width="40%">&nbsp;</td><td align="center" width="20%"><a accesskey="h" href="index.html">Home</a></td><td valign="top" align="right" width="40%">&nbsp;</td></tr></table></div></body></html>