CINXE.COM

Cocoon 2.2 Site - Your first Cocoon application using Maven 2

<div style='font-size:x-large;padding:15px;color:white;background:red;z-index:99;'> This project has retired. For details please refer to its <a style='color:white;text-decoration:underline' href="https://attic.apache.org/projects/cocoon.html"> Attic page</a>. </div><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <html> <head> <title> Cocoon 2.2 Site - Your first Cocoon application using Maven 2 </title> <link rel="stylesheet" href="./css/apache-cocoon-thien-maven-skin.min.css" /> <link rel="stylesheet" href="./css/print.css" type="text/css" media="print" /> <script src="./js/apache-cocoon-thien-maven-skin.min.js" language="javascript" type="text/javascript"></script> <meta name="author" content="Apache Cocoon Documentation Team" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body onload="javascript:prettyPrint();"> <div id="breadtrail"> <p><a href="http://www.apache.org">Apache</a> &raquo; <a href="../">Cocoon</a> &raquo;</p> </div> <div id="top"> <div id="header"> <div class="projectlogo"> <a href="../"><img class="logoImage" src="images/cocoon_logo.jpg" alt="Apache Cocoon" border="0" /></a> </div> <div class="grouplogo"> <p class="grouptitle"><a href="../">The Apache Cocoon Project</a><img src="images/apache-logo.jpg" alt="Cocoon Project Logo" /></p> <form class="searchbox" action="http://www.google.com/search" method="get"> <input value="cocoon.apache.org" name="sitesearch" type="hidden" /> <input onFocus="getBlank (this, 'Search the site with google');" size="25" name="q" id="query" type="text" value="Search the site with google" />&nbsp; <input class="searchboxsubmit" name="Search" value="Search" type="submit" /> </form> </div> </div> <div id="projectBar"> <p class="cocoonHome"><a href="./index.html"><img src="images/pmc-home.gif" alt=" Cocoon 2.2 homepage" border="0" title=" Cocoon 2.2 homepage" /></a></p> <h1 class="projectTitle"><a href="./index.html"> Cocoon 2.2 </a></h1> <ul class="projectList"> <li><strong><a href="../2.2/">Cocoon 2.2</a></em></strong></li> <li><a href="../2.2/core-modules/">Core <span class="pl-version-small">2.2</span></a></li> <li><a href="../2.2/blocks/">Blocks <span class="pl-version-small">2.2</span></a></li> <li><a href="../2.2/maven-plugins/">Maven Plugins <span class="pl-version-small">2.2</span></a></li> <li><strong><a href="..//3.0/">Cocoon 3.0</a></em></strong></li> <li><strong><a href="../subprojects/">Subprojects</a></strong></li> </ul> </div> <div class="projectBarClear"><!-- --></div> </div> <!-- end of top --> <div id="content"> <ul id="menu"> <li> Cocoon 2.2 <ul> <li > <a href="index.html">Overview</a> </li> <li > <a href="1447_1_1.html">Download</a> </li> <li > <a href="1420_1_1.html">New in 2.2</a> </li> </ul> </li> <li> Tutorials <ul> <li > <strong>Your first Cocoon application using Maven 2</strong> </li> <li > <a href="1290_1_1.html">Your first XML pipeline (publishing)</a> </li> <li > <a href="1291_1_1.html">Modularize Cocoon apps (Using blocks)</a> </li> <li > <a href="1362_1_1.html">Deploying a Cocoon application</a> </li> <li > <a href="1448_1_1.html">Screencasts</a> </li> </ul> </li> <li> How-Tos <ul> <li > <a href="1366_1_1.html">How to configure consistent encoding in Cocoon</a> </li> </ul> </li> <li> All Sitemap Components <ul> <li > <a href="1347_1_1.html">All Sitemap Components</a> </li> </ul> </li> </ul> <div class="main"> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <div id="contentBody"><div id="bodyText"><h1 class="docTitle">Your first Cocoon application using Maven 2</h1><p>In this tutorial, you will:</p><ol style="list-style-type: decimal"> <li>Create a Cocoon block (the application resources and logic)</li> <li>Import the block as a project in Eclipse</li> <li>Start the block as a web application and access it from your browser</li> </ol><div class="note"><div><b>Note: </b>First, make sure that you have Maven 2.0.9 or above installed. You can check this by calling <tt>mvn --version</tt> from the command line. If this doesn't work for you, read the <a class="externalLink" href="http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html">Maven in 5 Minutes</a> tutorial.</div></div><h1>Creating a Cocoon block</h1>Create a new directory which will be the root directory of your Cocoon application and change into it. For this tutorial, let's name it <tt>getting-started-app</tt>.The next step is to create a Cocoon block to contain your custom application. The development of any Cocoon web application should be done within one or more&#xa0; blocks.&#xa0; Cocoon blocks are little different to other Maven blocks except they have a particular expected <a href="../2.2/core-modules/core/2.2/1263_1_1.html">directory and file structure</a>.<div class="note"><div><b>Note: </b>You could manually create your blocks, but a simpler and less error-prone process is to use Maven's 'archetype' plugin.&#xa0; This allows you to select from a list of block types and have Maven create them for you.&#xa0; By default, the list of Maven archetypes is quite large.&#xa0; For convenience, a catalog of Cocoon specific archetypes is available on the Cocoon web site and you will make use of this in the following instructions.</div></div>Run the following Maven command:<div><pre>mvn archetype:generate -DarchetypeCatalog=http://cocoon.apache.org </pre></div><p>Maven will generate some output and then interactively ask you for some information:</p><div><pre>Choose archetype: 1: remote -&gt; cocoon-22-archetype-block-plain (Creates an empty Cocoon block; useful &#xa0;if you want to add another block to a Cocoon application) 2: remote -&gt; cocoon-22-archetype-block (Creates a Cocoon block containing some small &#xa0;samples) 3: remote -&gt; cocoon-22-archetype-webapp (Creates a web application configured to host Cocoon blocks. Just add the block dependencies) Choose a number: (1/2/3): <b>2</b> </pre></div><p>Maven first asks which archetype you want to create.&#xa0; Item 2 in this list is the standard Cocoon block with some small sample files already in place.</p><div><pre>Define value for groupId: : <b>com.mycompany</b> Define value for artifactId: : <b>myBlock1</b> Define value for version: 1.0-SNAPSHOT: : <b>1.0.0</b> Define value for package: : <b>com.mycompany.myBlock1</b><b><b> </b></b></pre></div><p>Maven then asks a few more questions.&#xa0; Just enter the details as shown above.&#xa0; The groupId is a label that you can use to group all the blocks in your application.&#xa0; The artifactId is the unique label that will identify this block from all others.&#xa0; It is also the name of the directory that will be created to contain the block's files.&#xa0; The package is the Java package that any Java files in the block will be assigned to.</p><div class="note"><div><b>Note: </b>If you are using a cocoon binary build from svn trunk then you probably want to change the archetypeVersion to the most recent one, matching the svn trunk. (see <tt>[<tt>c</tt></tt><tt>ocoon-svn]/tools/archetypes/cocoon-22-archetype-block/pom.xml</tt>) </div></div><p>Looking at the filesystem, you should find following directory structure:</p><div><pre>getting-started-app <tt>&#xa0;+-</tt><tt>myBlock1 +-pom.xml +-src +-[...] </tt></pre></div><h1>Import the block in Eclipse</h1><div class="note"><div><b>Note: </b>Cocoon is not tied to Eclipse IDE by any means. This step only describes what can be done to avoid tedious work of setting up project in Eclipse manually.<br /> If you don't use Eclipse, you can either skip this step or find a similar procedure to load the block in the IDE of your choice.</div></div><p>Change into the <tt>myBlock1</tt> directory and call</p><div><pre>mvn eclipse:eclipse</pre></div><p>This will create the necessary project descriptors for Eclipse. In Eclipse you can import the project into your workspace: <i>File &gt;&#xa0; Import... &gt; Existing Projects into Workspace</i></p><p>If that's the first time you use Eclipse together with a project created by Maven 2, we recommend you read the <a class="externalLink" href="http://maven.apache.org/guides/mini/guide-ide-eclipse.html">Maven Guide using Eclipse with Maven 2.x</a>.</p><h1>Run the block as Java web application</h1><p>After creating the Cocoon block you probably want to run it. For this purpose there is a Maven plugin that generates a minimal web application that loads your block. The pom.xml of your block already contains the necessary settings.</p><div><pre>mvn jetty:run</pre></div><p>and point your browser at <tt>http://localhost:8888/myBlock1/</tt> and get a hello world page.</p><div class="note"><div><b>Note: </b>The mentioned minimal web application is automatically created, when <tt>mvn jetty:run</tt> is invoked. This happens because the rcl goal of the Cocoon plugin is bound to the Maven build lifecycle which is invoked too, when the jetty:run goal is executed. See the block's <tt>pom.xml </tt>for details. </div></div><div class="note"><div><b>Note: </b>This process can be manually triggered with <tt>mvn cocoon:prepare</tt> too.</div></div><h1>Conclusion and further information</h1><p>So far you have created a Cocoon block and been able to run it in Jetty.&#xa0; This is only the first step to creating a full-blown Cocoon application.&#xa0; If you would like to know&#xa0; more read the following tutorials:</p><ul> <li><a href="1290_1_1.html">Your first XML pipeline</a><br /> Cocoon is well known for its XML pipelines.&#xa0; In this tutorial you will learn how to setup your first pipeline and discover the power of Cocoon sitemaps.</li> <li><a href="1291_1_1.html">Adding a second block</a><br /> This tutorial creates a web application that has a dependency on another block. There are use cases that require more than one block, e.g. you want to have all style specific resources within a single block that can be easily exchanged at deployment time (aka skinning).</li> <li><a href="../2.2/maven-plugins/maven-plugin/1.0/1297_1_1.html">Usage of the reloading classloader plugin</a><br /> The reloading classloader plugin enables rapid development of Cocoon applications since you don't have to restart the servlet container whenever one of your Java classes changes. Additionally, it enables the reloading of Cocoon resources too if they change.</li> <li><a href="1362_1_1.html">Deploying a Cocoon application<br /> </a>Eventually, you will probably need to create a Java web application (war file) in order to deploy your application to a servlet container such as Tomcat or Jetty, etc.&#xa0; This tutorial shows you how.<a href="../2.2/core-modules/core/2.2/1263_1_1.html"><br /> </a></li> </ul>For the time being, we <i>recommend</i> you use <i>Maven 2</i> as your build system (though there is no hard dependency on it). This has the advantage that the build system is standardized and Cocoon web applications can reuse the toolset (create Eclipse configuration files, create releases, produce documentation, etc.). More information about Maven 2 can be found at the project <a class="externalLink" href="http://maven.apache.org">website</a>.&#xa0; We especially recommend reading: <ul> <li> <a class="externalLink" href="http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html">Maven in 5 minutes</a> and the</li> <li><a class="externalLink" href="http://maven.apache.org/guides/getting-started/index.html">Getting started guide</a></li> </ul></div></div> </div> </div> <!-- end of content --> <div id="footer"> <p>Copyright &copy; 1999-2012 The Apache Software Foundation All Rights Reserved.</p> <p> Apache Cocoon, Apache, the Apache feather logo, and the Apache Cocoon project logos are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners. </p> </div> </script> <script type="text/javascript"> _uacct = "UA-1740622-3"; urchinTracker(); </script> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10