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: BD: Tutorial: Creating, extending and running a block
Date Wed, 11 Jan 2006 21:09:59 GMT
A new document has been created.

http://cocoon.zones.apache.org/daisy/documentation/796.html

Document ID: 796
Branch: main
Language: default
Name: BD: Tutorial: Creating, extending and running a block
Document Type: Cocoon Document
Created: 1/11/06 9:09:41 PM
Creator (owner): Reinhard Pötz
State: publish

Parts
=====

Content
-------
Mime type: text/xml
Size: 4889 bytes
Content:
<html>
<body>

<p class="fixme">This page contains mostly pseudo code for now. This will of
course change so that readers can follow the tutorial step by step.</p>

<p>This document describes how you can use <strong>Maven 2 </strong>to develop
your <strong>Cocoon 2.2 </strong>applications. It describes following steps:</p>

<ul>
<li>creating your block skeleton</li>
<li>configuring your block in general (dependencies on other blocks and
libraries, ...)</li>
<li>running your block without having to grapple with servlet containers or Java
web applications (war files)</li>
<li>extending your block (own pipelines and components)</li>
<li>installing your block to your local Maven repository</li>
</ul>

<h1>Install Maven 2</h1>

<p>Make sure that you have installed Maven 2. If you are not sure, open a
console and enter</p>

<pre>$ mvn -version
Maven version: 2.0
</pre>

<p>If this doesn't work, install Maven 2 first. There is an
<a href="http://maven.apache.org/guides/getting-started/index.html">Getting
Started Guide</a> that describes this in great detail.</p>

<h1>Create your block skeleton</h1>

<p>A Cocoon 2.2 application is a composition of blocks. This means that
everything that should run based on Cocoon 2.2 is a block. So what you need is
creating your own block. Cocoon 2.2 provides an Maven archetype that creates a
skeleton that already contains a working block. In order to use it, open an
console window, create an empty directory and enter</p>

<pre>mvn archetype:create \
  -DarchetypeGroupId=org.apache.cocoon \
  -DarchetypeArtifactId=block \ 
  -DarchetypeVersion=1.0 \
  -DgroupId=com.mycompany \
  -DartifactId=myBlock</pre>

<p class="fixme"><em>explain the directory structure, and explain what block.xml
and pom.xml are for.</em></p>

<h1>Run your block</h1>

<p>You want to see your new block it in action? You are only one command away!
Move again into the root directory of your block and enter</p>

<pre>mvn cocoon:simple-deploy jetty6:run
</pre>

<p>Open your favorite browser and enter</p>

<pre>http://localhost:8080/myBlock/</pre>

<h1>Use other blocks from within your block</h1>

<h2>Configure your block to use other blocks</h2>

<p>The main configuration file of a block is block.xml. It contains</p>

<ul>
<li>general information about the block (name, author, licencse, state, ...)
</li>
<li>path to the block's base sitemap</li>
<li>properties</li>
<li>requirements of other blocks (dependencies)</li>
<li>implemented contracts</li>
</ul>

<p>If you want, that your block depends on another block, it has to point to it:
</p>

<pre>&lt;block xmlns=""&gt;
 ...
 &lt;requirements&gt;
   &lt;requires 
      interface="http://the-contract-URI"
      name="xyz"
      default="my-group:my-artifact:1.0.2"/&gt;
   &lt;/requires&gt;
 &lt;requirements&gt;
 ...
&lt;/block&gt;
 </pre>

<p>If you have compile-time dependencies on the required blocks, you also have
to add the dependency to pom.xml:</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;dependencies&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;my-group&lt;/groupId&gt;
      &lt;artifactId&gt;my-artifact&lt;/artifactId&gt;
      &lt;version&gt;1.0.2&lt;/version&gt;
      &lt;scope&gt;test&lt;/scope&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
  &lt;/dependencies&gt;
  ...
&lt;/project&gt;
</pre>

<p class="note">If your block doesn't have a compile-time dependency, you don't
need to add it as Maven dependency.</p>

<h2>Create project descriptors for Eclipse and IDEA</h2>

<p>So far you have only been using the block skeleton provided by the Maven
archetype. That's fine but I'm sure you want to do more. So let's extend the
existing block a bit and also implement a Cocoon action.</p>

<p>If you want to use Eclipse or IDEA, Maven already provides the necessary
goals to create the project files:</p>

<pre>mvn eclipse:eclipse</pre>

<p>or</p>

<pre>mvn idea:idea</pre>

<h2>Use a pipeline of another block</h2>

<p>TBD</p>

<h2>Use a component of another block</h2>

<p>TBD</p>

<h2>Write your own component that can be used from another block</h2>

<p>TBD</p>

<h1>Install your block into your local Maven 2 repository</h1>

<p>In order to make your block locally available, you have to install it into
your local Maven 2 repository:<br/>
mvn install<br/>
This step is necessary, if you want to continue with the second tutorial
"[link_and_name".</p>

<h1>Further readings</h1>

<p>If you want to know more about Maven 2 than this document explains, have a
look at the <a href="http://maven.apache.org/">Maven documentation </a>and
especially the excellent Maven 2
<a href="http://maven.apache.org/guides/getting-started/index.html">Getting
Started Guide</a>.</p>

</body>
</html>

Collections
===========
The document belongs to the following collections: documentation

Mime
View raw message