WARNING: you are not looking at the live version but at an older version.

Your first Cocoon application using Maven 2

In this tutorial, you will:

  1. Create a Cocoon block (the application resources and logic)
  2. Start the block as web application and access it from your browser

Creating a block

The next step is creating a Cocoon block which will contain your custom application. The development of any Cocoon web application should be done within a block. Again, for this purpose there is a Maven archetype:

mvn archetype:create
  -DarchetypeGroupId=org.apache.cocoon
  -DarchetypeArtifactId=cocoon-22-archetype-block
  -DarchetypeVersion=1.0.0-M5
  -DgroupId=com.mycompany
  -DartifactId=myBlock1 

Once again for copy and paste without line feeds:
mvn archetype:create -DarchetypeGroupId=org.apache.cocoon -DarchetypeArtifactId=cocoon-22-archetype-block -DarchetypeVersion=1.0.0-M5 -DgroupId=com.mycompany -DartifactId=myBlock1

Change into the myBlock1 directory and call

mvn install

from there. This installs the block into your local Maven repository in ~/.m2/repository.

Looking at the filesystem, you should find following directory structure:

getting-started-app
 +-myCocoonWebapp
 |  +-pom.xml
 |  +-src
 |     +-[...]
 +-myBlock1
    +-pom.xml
    +-src
       +-[...]

As you can see,  the web application and the block are at the same level.

Run the block as Java web application

Explain cocoon:rcl, jetty:run + corresponding pom.xml sections here.

Conclusion and further information

So far you have created a Cocoon application that consists of a web application and a block. You have also been able to run the application in Jetty.
Probably you wonder how you can do some useful stuff like writing your own Cocoon pipeline or some Java code. For this purpose there are two more getting-started documents:

  • Your first XML pipeline
    Cocoon has become 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 sitemaps.
  • Adding a second block
    This tutorial created a web application that has a dependency on one 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 (-> skinning).
  • Usage of the reloading classloader plugin
    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.
  • Deploying a Cocoon application
    Although you have already been able to run this block, you most probably need a Java web application in order to deploy it in the servlet container of your choice.

For the time being, we recommend the usage of Maven 2 as 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 (creating Eclipse configuration files, releasing, create documentation, etc.) that Maven offers. More inforamtion about maven can be found at the project website. Especially we recommend

Comments (4)