A new document has been created. http://cocoon.zones.apache.org/daisy/documentation/1362.html
Document ID: 1362 Branch: main Language: default Name: Deploying a Cocoon application Document Type: Cocoon Document Created: 5/5/07 12:52:21 PM Creator (owner): Reinhard Pötz State: publish Parts ===== Content ------- Mime type: text/xml Size: 5495 bytes Content: <html> <body> <p>In this tutorial, you will:</p> <ol> <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> </ol> <h1>Creating a Cocoon web application</h1> <p>First, make sure that you have Maven 2.0.6 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> <h1>Using a block within the 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> and <tt>myBlock2</tt>. Change this by opening <tt>getting-started-app/myCocoonWebapp/pom.xml</tt> and add the block as dependency:</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> <dependency> <strong> <groupId><strong><tt>com.mycompany</tt></strong></groupId> <artifactId><strong>myBlock2</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"> [...] <strong> <parent> <groupId>com.mycompany</groupId> <artifactId>getting-started-app</artifactId> <version>1-SNAPSHOT</version> </parent></strong> [...] </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 class="fixme">TBD</p> </body> </html> Collections =========== The document belongs to the following collections: documentation, cdocs-site-main