| <html><head> |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| <title>7.5 Adding the dependency plugin</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="Creating an application with EclipseRT Virgo Web Server"><link rel="up" href="ch07.html" title="7. Automated Build"><link rel="prev" href="ch07s04.html" title="7.4 Adding the par plugin"><link rel="next" href="ch07s06.html" title="7.6 Automatically running the tests"><!--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">7.5 Adding the dependency plugin</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch07s04.html">Prev</a> </td><th width="60%" align="center">7. Automated Build</th><td width="20%" align="right"> <a accesskey="n" href="ch07s06.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="automated.build.dependency.plugin"></a>7.5 Adding the <code class="literal">dependency</code> plugin</h2></div></div></div><p> |
| Maven now successfully builds the PAR for the application, however the dependencies of the PAR |
| are not apparent. |
| In this step the Maven <code class="literal">dependency</code> plugin is added to |
| collect the transitive dependency graph for the PAR. |
| </p><p> |
| In the <code class="literal"><build><plugins>…</plugins></build></code> section |
| (after the <code class="literal">par</code> plugin |
| declaration), add a plugin 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>>com.springsource.dmserver,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> |
| A dependency on Freemarker needs to be added to the other dependencies. |
| This is required to ensure the Web |
| bundle has the correct set of dependencies as well as the other bundles. |
| Normally they would simply be 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. |
| For this reason its dependencies must be given explicitly. |
| </p><pre class="programlisting"><<span class="hl-comment">!-- Required for the web bundle as dependencies are not propagated up from war build types --</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>> |
| </pre><p> |
| </p><p> |
| The next step is to stop the Web bundle including its dependencies in a lib directory as they will be provided |
| by the runtime enviroment. Add the following build section to the <code class="literal">greenpages.web</code> POM file. |
| </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><p> |
| Run the following command. |
| </p><pre class="programlisting">mvn clean package</pre><p> |
| </p><p> |
| When the command has completed, it will have copied all of the PAR’s dependencies into the |
| <code class="filename">target/par-provided</code> directory. |
| The output from Maven should include lines like these |
| </p><pre class="programlisting">[INFO] [par:par] |
| [INFO] Assembling Artifacts for PAR '/Users/chrisfrost/Repos/GIT/greenpages/solution/ |
| greenpages/target/greenpages-solution-2.3.0.RELEASE.par' |
| [INFO] Added 'greenpages.app-solution.jar' |
| [INFO] Added 'greenpages.jpa-solution.jar' |
| [INFO] Added 'greenpages.db-solution.jar' |
| [INFO] Added 'greenpages.web-solution.war' |
| </pre><p> |
| If the dependencies are produced, proceed to the next step. |
| </p></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="ch07s04.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch07.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch07s06.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">7.4 Adding the par plugin </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 7.6 Automatically running the tests</td></tr></table></div></body></html> |