| <html><head> |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| <title>3.4 Automated Build Highlights</title><link rel="stylesheet" href="css/stylesheet.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.74.0"><link rel="home" href="index.html" title="A Guide to the GreenPages Sample"><link rel="up" href="ch03.html" title="3. GreenPages Highlights"><link rel="prev" href="ch03s03.html" title="3.3 Testing Highlights"><link rel="next" href="apa.html" title="Appendix A. Further Resources"><!--Begin Google Analytics code--><script type="text/javascript"> |
| var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); |
| document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); |
| </script><script type="text/javascript"> |
| var pageTracker = _gat._getTracker("UA-2728886-3"); |
| pageTracker._setDomainName("none"); |
| pageTracker._setAllowLinker(true); |
| pageTracker._trackPageview(); |
| </script><!--End Google Analytics code--></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">3.4 Automated Build Highlights</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch03s03.html">Prev</a> </td><th width="60%" align="center">3. GreenPages Highlights</th><td width="20%" align="right"> <a accesskey="n" href="apa.html">Next</a></td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="highlights.automated.build"></a>3.4 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’s IDE. The application can then be |
| created and tested in a variety of environments, including continuous integration servers. |
| </p><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1228"></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"><<span class="hl-tag">parent</span>> |
| <<span class="hl-tag">groupId</span>>org.eclipse.virgo<<span class="hl-tag">/groupId</span>> |
| <<span class="hl-tag">artifactId</span>>greenpages.parent<<span class="hl-tag">/artifactId</span>> |
| <<span class="hl-tag">version</span>>2.4.0.RELEASE<<span class="hl-tag">/version</span>> |
| <<span class="hl-tag">relativePath</span>>../greenpages.parent<<span class="hl-tag">/relativePath</span>> |
| <<span class="hl-tag">/parent</span>> |
| |
| <<span class="hl-tag">modelVersion</span>>4.0.0<<span class="hl-tag">/modelVersion</span>> |
| <<span class="hl-tag">groupId</span>>org.eclipse.virgo<<span class="hl-tag">/groupId</span>> |
| <<span class="hl-tag">artifactId</span>>greenpages<<span class="hl-tag">/artifactId</span>> |
| <<span class="hl-tag">name</span>>GreenPages PAR<<span class="hl-tag">/name</span>> |
| <<span class="hl-tag">description</span>>GreenPages PAR<<span class="hl-tag">/description</span>> |
| <<span class="hl-tag">packaging</span>>par<<span class="hl-tag">/packaging</span>> |
| </pre><p> |
| </p><p> |
| Thorsten Maus created a Maven plugin (see <a class="xref" href="apas02.html" title="A.2 Documentation">Section A.2, “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"><<span class="hl-tag">dependencies</span>> |
| <<span class="hl-tag">dependency</span>> |
| <<span class="hl-tag">groupId</span>>org.eclipse.virgo<<span class="hl-tag">/groupId</span>> |
| <<span class="hl-tag">artifactId</span>>greenpages.app<<span class="hl-tag">/artifactId</span>> |
| <<span class="hl-tag">version</span>>${project.version}<<span class="hl-tag">/version</span>> |
| <<span class="hl-tag">/dependency</span>> |
| <<span class="hl-tag">dependency</span>> |
| <<span class="hl-tag">groupId</span>>org.eclipse.virgo<<span class="hl-tag">/groupId</span>> |
| <<span class="hl-tag">artifactId</span>>greenpages.jpa<<span class="hl-tag">/artifactId</span>> |
| <<span class="hl-tag">version</span>>${project.version}<<span class="hl-tag">/version</span>> |
| <<span class="hl-tag">/dependency</span>> |
| <<span class="hl-tag">dependency</span>> |
| <<span class="hl-tag">groupId</span>>org.eclipse.virgo<<span class="hl-tag">/groupId</span>> |
| <<span class="hl-tag">artifactId</span>>greenpages.db<<span class="hl-tag">/artifactId</span>> |
| <<span class="hl-tag">version</span>>${project.version}<<span class="hl-tag">/version</span>> |
| <<span class="hl-tag">/dependency</span>> |
| <<span class="hl-tag">dependency</span>> |
| <<span class="hl-tag">groupId</span>>org.eclipse.virgo<<span class="hl-tag">/groupId</span>> |
| <<span class="hl-tag">artifactId</span>>greenpages.web<<span class="hl-tag">/artifactId</span>> |
| <<span class="hl-tag">version</span>>${project.version}<<span class="hl-tag">/version</span>> |
| <<span class="hl-tag">type</span>>war<<span class="hl-tag">/type</span>> |
| <<span class="hl-tag">/dependency</span>> |
| <<span class="hl-tag">dependency</span>> |
| <<span class="hl-tag">groupId</span>>org.freemarker<<span class="hl-tag">/groupId</span>> |
| <<span class="hl-tag">artifactId</span>>com.springsource.freemarker<<span class="hl-tag">/artifactId</span>> |
| <<span class="hl-tag">scope</span>>provided<<span class="hl-tag">/scope</span>> |
| <<span class="hl-tag">/dependency</span>> |
| <<span class="hl-tag">/dependencies</span>> |
| </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 ‘war’ 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"><build><plugins>…</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"><<span class="hl-tag">plugin</span>> |
| <<span class="hl-tag">groupId</span>>org.apache.maven.plugins<<span class="hl-tag">/groupId</span>> |
| <<span class="hl-tag">artifactId</span>>maven-par-plugin<<span class="hl-tag">/artifactId</span>> |
| <<span class="hl-tag">version</span>>1.0.0.RELEASE<<span class="hl-tag">/version</span>> |
| <<span class="hl-tag">configuration</span>> |
| <<span class="hl-tag">applicationSymbolicName</span>>greenpages<<span class="hl-tag">/applicationSymbolicName</span>> |
| <<span class="hl-tag">/configuration</span>> |
| <<span class="hl-tag">/plugin</span>> |
| </pre><p> |
| </p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1269"></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"><build><plugins>…</code> section |
| has a declaration for the <code class="literal">dependency</code> plugin: |
| </p><pre class="programlisting"><<span class="hl-tag">plugin</span>> |
| <<span class="hl-tag">groupId</span>>org.apache.maven.plugins<<span class="hl-tag">/groupId</span>> |
| <<span class="hl-tag">artifactId</span>>maven-dependency-plugin<<span class="hl-tag">/artifactId</span>> |
| <<span class="hl-tag">executions</span>> |
| <<span class="hl-tag">execution</span>> |
| <<span class="hl-tag">id</span>>copy-dependencies<<span class="hl-tag">/id</span>> |
| <<span class="hl-tag">phase</span>>package<<span class="hl-tag">/phase</span>> |
| <<span class="hl-tag">goals</span>> |
| <<span class="hl-tag">goal</span>>copy-dependencies<<span class="hl-tag">/goal</span>> |
| <<span class="hl-tag">/goals</span>> |
| <<span class="hl-tag">configuration</span>> |
| <<span class="hl-tag">outputDirectory</span>>${project.build.directory}/par-provided<<span class="hl-tag">/outputDirectory</span>> |
| <<span class="hl-tag">overWriteIfNewer</span>>true<<span class="hl-tag">/overWriteIfNewer</span>> |
| <<span class="hl-tag">excludeGroupIds</span>>org.eclipse.virgo,org.apache.log4j<<span class="hl-tag">/excludeGroupIds</span>> |
| <<span class="hl-tag">/configuration</span>> |
| <<span class="hl-tag">/execution</span>> |
| <<span class="hl-tag">/executions</span>> |
| <<span class="hl-tag">/plugin</span>> |
| </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"><<span class="hl-tag">build</span>> |
| <<span class="hl-tag">plugins</span>> |
| <<span class="hl-tag">plugin</span>> |
| <<span class="hl-tag">artifactId</span>>maven-war-plugin<<span class="hl-tag">/artifactId</span>> |
| <<span class="hl-tag">version</span>>2.1-beta-1<<span class="hl-tag">/version</span>> |
| <<span class="hl-tag">configuration</span>> |
| <<span class="hl-tag">packagingExcludes</span>>WEB-INF/lib/**<<span class="hl-tag">/packagingExcludes</span>> |
| <<span class="hl-tag">/configuration</span>> |
| <<span class="hl-tag">/plugin</span>> |
| <<span class="hl-tag">/plugins</span>> |
| <<span class="hl-tag">/build</span>></pre><p> |
| </p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="d0e1299"></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"><<span class="hl-tag">plugin</span>> |
| <<span class="hl-tag">groupId</span>>org.apache.maven.plugins<<span class="hl-tag">/groupId</span>> |
| <<span class="hl-tag">artifactId</span>>maven-surefire-plugin<<span class="hl-tag">/artifactId</span>> |
| <<span class="hl-tag">configuration</span>> |
| <<span class="hl-tag">includes</span>> |
| <<span class="hl-tag">include</span>>**/*Tests.java<<span class="hl-tag">/include</span>> |
| <<span class="hl-tag">/includes</span>> |
| <<span class="hl-tag">excludes</span>> |
| <<span class="hl-tag">exclude</span>>**/Abstract*.java<<span class="hl-tag">/exclude</span>> |
| <<span class="hl-tag">/excludes</span>> |
| <<span class="hl-tag">junitArtifactName</span>>org.junit:com.springsource.org.junit<<span class="hl-tag">/junitArtifactName</span>> |
| <<span class="hl-tag">argLine</span>>-javaagent:${user.home}/.m2/repository/…<<span class="hl-tag">/argLine</span>> |
| <<span class="hl-tag">/configuration</span>> |
| <<span class="hl-tag">/plugin</span>> |
| </pre><p> |
| The location of the user's Maven repository is hard-coded. |
| </p></div></div><!--Begin LoopFuse code--><script src="http://loopfuse.net/webrecorder/js/listen.js" type="text/javascript"></script><script type="text/javascript"> |
| _lf_cid = "LF_48be82fa"; |
| _lf_remora(); |
| </script><!--End LoopFuse code--><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch03s03.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch03.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="apa.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">3.3 Testing Highlights </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Appendix A. Further Resources</td></tr></table></div></body></html> |