blob: e8cfd3c8dec16a120279f3bdcbd853854354f7dc [file] [log] [blame]
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>7.5&nbsp;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.&nbsp;Automated Build"><link rel="prev" href="ch07s04.html" title="7.4&nbsp;Adding the par plugin"><link rel="next" href="ch07s06.html" title="7.6&nbsp;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&nbsp;Adding the dependency plugin</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch07s04.html">Prev</a>&nbsp;</td><th width="60%" align="center">7.&nbsp;Automated Build</th><td width="20%" align="right">&nbsp;<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&nbsp;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">&lt;build&gt;&lt;plugins&gt;&#8230;&lt;/plugins&gt;&lt;/build&gt;</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">&lt;<span class="hl-tag">plugin</span>&gt;
&lt;<span class="hl-tag">groupId</span>&gt;org.apache.maven.plugins&lt;<span class="hl-tag">/groupId</span>&gt;
&lt;<span class="hl-tag">artifactId</span>&gt;maven-dependency-plugin&lt;<span class="hl-tag">/artifactId</span>&gt;
&lt;<span class="hl-tag">executions</span>&gt;
&lt;<span class="hl-tag">execution</span>&gt;
&lt;<span class="hl-tag">id</span>&gt;copy-dependencies&lt;<span class="hl-tag">/id</span>&gt;
&lt;<span class="hl-tag">phase</span>&gt;package&lt;<span class="hl-tag">/phase</span>&gt;
&lt;<span class="hl-tag">goals</span>&gt;
&lt;<span class="hl-tag">goal</span>&gt;copy-dependencies&lt;<span class="hl-tag">/goal</span>&gt;
&lt;<span class="hl-tag">/goals</span>&gt;
&lt;<span class="hl-tag">configuration</span>&gt;
&lt;<span class="hl-tag">outputDirectory</span>&gt;${project.build.directory}/par-provided&lt;<span class="hl-tag">/outputDirectory</span>&gt;
&lt;<span class="hl-tag">overWriteIfNewer</span>&gt;true&lt;<span class="hl-tag">/overWriteIfNewer</span>&gt;
&lt;<span class="hl-tag">excludeGroupIds</span>&gt;com.springsource.dmserver,org.apache.log4j&lt;<span class="hl-tag">/excludeGroupIds</span>&gt;
&lt;<span class="hl-tag">/configuration</span>&gt;
&lt;<span class="hl-tag">/execution</span>&gt;
&lt;<span class="hl-tag">/executions</span>&gt;
&lt;<span class="hl-tag">/plugin</span>&gt;
</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 &#8216;war&#8217; project does not pass on its dependencies;
it expects
them to be contained in its &#8216;lib&#8217; directory.
For this reason its dependencies must be given explicitly.
</p><pre class="programlisting">&lt;<span class="hl-comment">!-- Required for the web bundle as dependencies are not propagated up from war build types --</span>&gt;
&lt;<span class="hl-tag">dependency</span>&gt;
&lt;<span class="hl-tag">groupId</span>&gt;org.freemarker&lt;<span class="hl-tag">/groupId</span>&gt;
&lt;<span class="hl-tag">artifactId</span>&gt;com.springsource.freemarker&lt;<span class="hl-tag">/artifactId</span>&gt;
&lt;<span class="hl-tag">scope</span>&gt;provided&lt;<span class="hl-tag">/scope</span>&gt;
&lt;<span class="hl-tag">/dependency</span>&gt;
</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">&lt;<span class="hl-tag">build</span>&gt;
&lt;<span class="hl-tag">plugins</span>&gt;
&lt;<span class="hl-tag">plugin</span>&gt;
&lt;<span class="hl-tag">artifactId</span>&gt;maven-war-plugin&lt;<span class="hl-tag">/artifactId</span>&gt;
&lt;<span class="hl-tag">version</span>&gt;2.1-beta-1&lt;<span class="hl-tag">/version</span>&gt;
&lt;<span class="hl-tag">configuration</span>&gt;
&lt;<span class="hl-tag">packagingExcludes</span>&gt;WEB-INF/lib/**&lt;<span class="hl-tag">/packagingExcludes</span>&gt;
&lt;<span class="hl-tag">/configuration</span>&gt;
&lt;<span class="hl-tag">/plugin</span>&gt;
&lt;<span class="hl-tag">/plugins</span>&gt;
&lt;<span class="hl-tag">/build</span>&gt;</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&#8217;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>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="ch07.html">Up</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="ch07s06.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">7.4&nbsp;Adding the par plugin&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;7.6&nbsp;Automatically running the tests</td></tr></table></div></body></html>