A document has been updated: http://cocoon.zones.apache.org/daisy/documentation/1159.html
Document ID: 1159 Branch: main Language: default Name: Your first Cocoon application using Maven 2 (unchanged) Document Type: Cocoon Document (unchanged) Updated on: 5/5/07 1:03:17 PM Updated by: Reinhard Pötz A new version has been created, state: publish Parts ===== Content ------- This part has been updated. Mime type: text/xml (unchanged) File name: (unchanged) Size: 4421 bytes (previous version: 10039 bytes) Content diff: (3 equal lines skipped) <p>In this tutorial, you will:</p> <ol> --- <li>Create two Maven modules: a Cocoon web application (mounted in a servlet --- container), and a Cocoon block (the application resources and logic)</li> --- <li>Connect the block to the webapp and run it</li> --- <li>Create a parent Maven POM for the webapp and block (a convenience which --- allows you to trigger cascading builds of both maven modules from a single --- command)</li> --- <li>Change the block mount point so that it is mounted at the root level context --- (typical for a web application "main block")</li> +++ <li>Create a Cocoon block (the application resources and logic)</li> +++ <li>Start the block as web application</li> </ol> --- <h1>Creating a Cocoon web application</h1> --- --- <p>First, make sure that you have Maven 2.0.4 or above installed. You can check --- this by calling</p> --- --- <pre>mvn --version</pre> --- --- <p>from command line. If this doesn't work for you, read the --- <a href="http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html">Maven --- in 5 Minutes</a> tutorial.</p> --- --- <p>Next create a new directory which will be the root directory of your Cocoon --- application. For this tutorial, let's name it <tt>getting-started-app</tt>. --- Change into it and invoke the <tt>cocoon-22-archetype-webapp</tt> archetype:</p> --- --- <pre>mvn archetype:create --- -DarchetypeGroupId=org.apache.cocoon --- -DarchetypeArtifactId=cocoon-22-archetype-webapp --- -DarchetypeVersion=1.0.0-M2 --- -DgroupId=com.mycompany --- -DartifactId=<tt>myCocoonWebapp</tt> --- </pre> --- --- <p class="note">For copy and paste without line feeds:<br/> --- <tt>mvn archetype:create -DarchetypeGroupId=org.apache.cocoon --- -DarchetypeArtifactId=cocoon-22-archetype-webapp -DarchetypeVersion=1.0.0-M2 --- -DgroupId=com.mycompany -DartifactId=</tt><tt>myCocoonWebapp</tt></p> --- --- <p>Because of a Maven bug, it could be necessary to add the apache.snapshots --- Maven repository to <tt>getting-started-app/myCocoonWebapp/pom.xml</tt>:</p> --- --- <pre><repositories> --- [...] --- <repository> --- <id>apache.snapshot</id> --- <name>Apache Snapshot Repository</name> --- <url>http://people.apache.org/repo/m2-snapshot-repository</url> --- <releases> --- <!-- excalibur poms are located here --> --- <enabled>true</enabled> --- </releases> --- <snapshots> --- <enabled>true</enabled> --- </snapshots> --- </repository> --- [...] --- </repositories> --- </pre> --- --- <p>The next release of the archetype will already have set the repository --- settings.</p> --- <h1>Creating a block</h1> <p>The next step is creating a Cocoon block which will contain your custom (59 equal lines skipped) <p>As you can see, the web application and the block are at the same level.</p> --- <h1>Using the block within the web application</h1> +++ <h1>Run the block as Java web application</h1> --- <p>So far the web application <tt>myCocoonWebapp</tt> doesn't have any --- information about the existense of the block <tt>myBlock1</tt>. Change this by --- opening <tt>getting-started-app/myCocoonWebapp/pom.xml</tt> and add the block as --- dependency:</p> +++ <p class="fixme">Explain cocoon:rcl, jetty:run + corresponding pom.xml sections +++ here.</p> --- <pre><project> --- [...] --- <dependencies> --- <dependency> --- <strong> <groupId><strong><tt>com.mycompany</tt></strong></groupId> --- <artifactId><strong>myBlock1</strong></artifactId> --- <version><strong>1.0-SNAPSHOT</strong></version></strong> --- </dependency> --- </dependencies> --- [...] --- </project></pre> --- --- <p>That's it. Now it's time to run the web application. Move into --- <tt>getting-started-app/myCocoonWebapp</tt> and call</p> --- --- <pre>mvn package jetty:run</pre> --- --- <p>from there.<br/> --- Open your favorite web browser and call</p> --- --- <pre>http://localhost:8888/myBlock1/</pre> --- --- <p>That's it!</p> --- --- <h1>Creating a parent pom</h1> --- --- <p>For your convenience you can create a parent pom for the two Maven modules. --- Create a file <tt>getting-started-app/pom.xml</tt> with following content:</p> --- --- <pre><project xmlns="http://maven.apache.org/POM/4.0.0" --- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" --- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> --- --- <modelVersion>4.0.0</modelVersion> --- <packaging>pom</packaging> --- --- <groupId>com.mycompany</groupId> --- <artifactId>getting-started-app</artifactId> --- <version>1-SNAPSHOT</version> --- --- <name>Cocoon Getting Stared application [parent]</name> --- --- <modules> --- <module><strong><tt>myCocoonWebapp</tt></strong></module> --- <module><strong>myBlock1</strong></module> --- </modules> --- </project> --- </pre> --- --- <p>Having a parent pom file, you can trigger a reactor build from root, e.g. you --- can call mvn install from root which will compile, package and install the --- webapp and the block. Maven also takes care that the modules are build, --- according to the dependency graph, in the correct order.</p> --- --- <p>If you want to inherit information (e.g. plugin configurations, properties, --- etc.) from the new parent pom to the two modules, you have to add the parent --- element to <tt>getting-started-app/myCocoonWebapp/pom.xml</tt> and --- <tt>getting-started-app/myBlock1/pom.xml</tt>:</p> --- --- <pre><project xmlns="http://maven.apache.org/POM/4.0.0" --- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" --- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> --- --- [...] --- <parent> --- <groupId>com.mycompany</groupId> --- <artifactId>getting-started-app</artifactId> --- <version>1-SNAPSHOT</version> --- </parent> --- [...] --- --- </project></pre> --- --- <h1>Mounting your block at the root level</h1> --- --- <p>You can mount your block at the root level in the application URI space, so --- that instead of using (for example) the URI --- <tt>http://localhost:8888/myBlock/foo/bar</tt> to request a page, you would --- request it at <tt>http://localhost:8888/foo/bar</tt>.</p> --- --- <p>To do this, edit myBlock/src/main/resources/META-INF/cocoon/spring/block.xml --- , and change the element</p> --- --- <pre> <property name="mountPath" value="/myBlock1"/> --- </pre> --- --- <p>to</p> --- --- <pre> <property name="mountPath" value=""/> --- </pre> --- --- <p>and then do <tt>mvn:install</tt>.</p> --- <h1>Conclusion and further information</h1> <p>So far you have created a Cocoon application that consists of a web (4 equal lines skipped) getting-started documents:</p> <ul> --- <li><a href="daisy:1297">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 provides all settings to enable --- the reload of Cocoon resources too.</li> <li><a href="daisy:1290">Your first XML pipeline</a><br/> Cocoon is famous for XML pipelines. At this tutorial you will learn how to setup your first pipeline and will learn the most important things about Cocoon (3 equal lines skipped) 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 (-> skinning).</li> +++ <li><a href="daisy:1297">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 provides all settings to enable +++ the reload of Cocoon resources too.</li> +++ <li><a href="daisy:1263">Deploying a Cocoon application<br/> +++ </a></li> </ul> <p>For the time being, we recommend the usage of Maven 2 as build system (though (16 equal lines skipped)