Your first Cocoon application using Maven 2
In this tutorial, you will:
- Create a Cocoon block (the application resources and logic)
- Import the block as project in Eclipse
- Start the block as web application and access it from your browser
Creating a block
mvn archetype:create -DarchetypeGroupId=org.apache.cocoon -DarchetypeArtifactId=cocoon-22-archetype-block -DarchetypeVersion=1.0.0-RC2 -DgroupId=com.mycompany -DartifactId=myBlock1
mvn archetype:create -DarchetypeGroupId=org.apache.cocoon -DarchetypeArtifactId=cocoon-22-archetype-block -DarchetypeVersion=1.0.0-RC2 -DgroupId=com.mycompany -DartifactId=myBlock1
getting-started-app
+-myBlock1
+-pom.xml
+-src
+-[...]
Import the block in Eclipse
If you don't use Eclipse, you can either skip this step or find a similar procedure to load the block in the IDE of your choice.
Change into the myBlock1 directory and call
mvn eclipse:eclipse
This will create the necessary project descriptors for Eclipse. In Eclipse you can import the project into your workspace: File - Import - General - Existing Projects.
If that's the first time you use Eclipse together with a project created by Maven 2, we recomment to read the Maven Guide using Eclipse with Maven 2.x.
Run the block as Java web application
After creating the block you probably want to run it. For this purpose there is a Maven plugin, that generates a minimal web application that loads your block. The pom.xml of your block already contains all necessary configurations.
You can then run
mvn jetty:run
and point your browser at http://localhost:8888/myBlock1/ and get a hello world page.
This process can be manually triggered with mvn cocoon:rcl too.
Conclusion and further information
So far you have created a block. You have also been able to run the block in Jetty. Of course, that was only the first step in order to get a "Hello world" as result. If you wonder how you can do some useful stuff like writing your own Cocoon pipeline or some Java code, there are more tutorials:
- 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
While following this tutorial, you will create 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 (aka 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 (war file) in order to deploy it to the servlet container (Tomcat, Jetty, etc.) of your choice.


