cocoon-docs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@cocoon.zones.apache.org
Subject [DAISY] Created: Deploying a Cocoon application
Date Sat, 05 May 2007 12:52:27 GMT
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>&lt;project&gt;
  [...]
    &lt;dependencies&gt;
      &lt;dependency&gt;
<strong>        &lt;groupId&gt;<strong><tt>com.mycompany</tt></strong>&lt;/groupId&gt;
        &lt;artifactId&gt;<strong>myBlock1</strong>&lt;/artifactId&gt;
        &lt;version&gt;<strong>1.0-SNAPSHOT</strong>&lt;/version&gt;</strong>
      &lt;/dependency&gt;
      &lt;dependency&gt;
<strong>        &lt;groupId&gt;<strong><tt>com.mycompany</tt></strong>&lt;/groupId&gt;
        &lt;artifactId&gt;<strong>myBlock2</strong>&lt;/artifactId&gt;
        &lt;version&gt;<strong>1.0-SNAPSHOT</strong>&lt;/version&gt;</strong>
      &lt;/dependency&gt;
    &lt;/dependencies&gt;
  [...]
&lt;/project&gt;</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>&lt;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"&gt;

  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;packaging&gt;pom&lt;/packaging&gt;
  
  &lt;groupId&gt;com.mycompany&lt;/groupId&gt;
  &lt;artifactId&gt;getting-started-app&lt;/artifactId&gt;
  &lt;version&gt;1-SNAPSHOT&lt;/version&gt;
  
  &lt;name&gt;Cocoon Getting Stared application [parent]&lt;/name&gt;
  
  &lt;modules&gt;
    &lt;module&gt;<strong><tt>myCocoonWebapp</tt></strong>&lt;/module&gt;
    &lt;module&gt;<strong>myBlock1</strong>&lt;/module&gt;
  &lt;/modules&gt;
&lt;/project&gt;
</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>&lt;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"&gt;

  [...]
<strong>  &lt;parent&gt;
    &lt;groupId&gt;com.mycompany&lt;/groupId&gt;
    &lt;artifactId&gt;getting-started-app&lt;/artifactId&gt;
    &lt;version&gt;1-SNAPSHOT&lt;/version&gt;
  &lt;/parent&gt;</strong>
  [...]

&lt;/project&gt;</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>    &lt;property name="mountPath" value="/myBlock1"/&gt;
</pre>

<p>to</p>

<pre>    &lt;property name="mountPath" value=""/&gt;
</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

Mime
View raw message