This how-to explains how to build Cocoon with Maven. An example for building a minimal webapp is provided for each option at the end of this document.
Maven is a Java project management and project comprehension tool that is used in many projects around the world. The intent of Maven is to make intra-project development highly manageable in the hopes of providing more time for cross-project development. See Maven's Goals.
There is really only one step to integrate Maven with a project: the creation of a project descriptor. You may also create an ancillar maven.xml file which contains project specific goals, preGoals, and postGoals.
If you are using Maven for the first time or starting a new project you can use the GenApp plug-in to automate the creation of a Maven project tree.
maven -Dpackage=com.mycompany.app genapp
I'll present two approaches that were discussed on the user mailing list http://marc.theaimsgroup.com/?t=110114687600005&r=1&w=2.
I used to build Cocoon this way before discovering Ralph's method. It consists mainly in manually tracking all the Cocoon's JARs and putting them into your Maven repository. Here the steps:
The drawback of this solution is the need to upgrade all the Cocoon blocks and dependencies with each release (It could be a real pain, believe me!). Ralph's approach solves this problem.
This method was introduced to me by RalphGoers (thanks Ralph!). It consists in building Cocoon and put the generated WAR file on your Maven repository.
Note that this means that the vast majority of the JARs you will be using will be brought in via the Cocoon WAR file, dramatically reducing the number of dependencies that have to be changed with each Cocoon update.
Option 1
Option 2
Note
Note
<dependencies> <dependency> <groupId>cocoon</groupId> <artifactId>cocoon-war</artifactId> <version>2.1.6</version> <type>war</type> </dependency> </dependencies> |
you may want to use the maven.xml below:
<?xml version="1.0" encoding="ISO-8859-1"?> <project default="war" xmlns:jelly="jelly:core"> <preGoal name="war:webapp"> <jelly:forEach var="dependency" items="${pom.dependencies}"> <jelly:if test="${dependency.getArtifactId().equals('cocoon-war')}"> <jelly:if test="${dependency.getType().equals('war')}"> <jelly:set var="cocoonWar" value="cocoon-war-${dependency.getVersion()}.war"/> <unwar src="${maven.repo.local}/cocoon/wars/${cocoonWar}" dest="${maven.build.dir}/${pom.artifactId}"> <echo>Extracting ${cocoonWar}</echo> </unwar> </jelly:if> </jelly:if> </jelly:forEach> </preGoal> </project> |