A document has been updated:

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

Document ID: 1159
Branch: main
Language: default
Name: Your first Cocoon application using Maven 2 (unchanged)
Document Type: Cocoon Document (unchanged)
Updated on: 12/28/06 4:13:52 PM
Updated by: Reinhard Pötz

A new version has been created, state: draft

Parts
=====

Content
-------
This part has been updated.
Mime type: text/xml (unchanged)
File name:  (unchanged)
Size: 5822 bytes (previous version: 3424 bytes)
Content diff:
(4 equal lines skipped)
    
    <h1>Creating a Cocoon web application</h1>
    
--- <ul>
--- <li>use the archetype</li>
--- </ul>
+++ <p>First, make sure that you have Maven 2.0.4 or above installed. You can 
check
+++ by calling</p>
    
--- <h1>Creating a block</h1>
+++ <pre>mvn --version</pre>
    
--- <ul>
--- <li>use the archetype</li>
--- <li>use mvn eclipse:eclipse</li>
--- <li>refer to RCL plugin tutorial</li>
--- </ul>
+++ <p>from command line.<br/>
+++ If that works for you, 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>. Move into it and invoke the
+++ <tt>cocoon-22-archetype-webapp</tt> archetype:</p>
    
--- <h1>Using the block within the web application</h1>
+++ <pre>mvn archetype:create
+++   -DarchetypeGroupId=org.apache.cocoon
+++   -DarchetypeArtifactId=cocoon-22-archetype-webapp
+++   -DarchetypeVersion=1.0.0-M1
+++   -DgroupId=com.mycompany
+++   -DartifactId=myWebapp
+++ </pre>
    
--- <ul>
--- <li>update POM</li>
--- <li>create a parent POM</li>
--- <li>use Jetty to run the application (note: not useful at development time) 
-
--- start browser</li>
--- <li>refer to usual Maven 2  mechanisms to build, package and release</li>
--- </ul>
+++ <p class="note">Once again 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-M1
+++ -DgroupId=com.mycompany -DartifactId=myCocoonWebapp</tt></p>
    
--- <p>Adding a second block</p>
+++ <h1>Creating a block</h1>
    
--- <ul>
--- <li>reasons why this can be useful</li>
--- <li>use the block archetype</li>
--- <li>update block bean definition of the first block</li>
--- </ul>
+++ <p>The next step is creating a Cocoon block which will contain your custom
+++ application. Remember, everything in Cocoon 2.2 is a block. Again, for this
+++ purpose there is a Maven archetype:</p>
    
--- <p class="warn">former version</p>
+++ <pre>mvn archetype:create
+++   -DarchetypeGroupId=org.apache.cocoon
+++   -DarchetypeArtifactId=cocoon-22-archetype-block
+++   -DarchetypeVersion=1.0.0-M4
+++   -DgroupId=com.mycompany
+++   -DartifactId=myBlock 
+++ </pre>
    
--- <p>A typical Cocoon application is divided into several projects: the web
--- application and the used blocks. For your own project you need a web 
application
--- project which depends on all the used blocks. If you want to split up your
--- application into different units, you might want to create your own 
blocks.</p>
+++ <p class="note">Once again for copy and paste without line feeds:<br/>
+++ <tt>mvn archetype:create -DarchetypeGroupId=org.apache.cocoon
+++ -DarchetypeArtifactId=cocoon-22-archetype-block -DarchetypeVersion=1.0.0-M4
+++ -DgroupId=com.mycompany -DartifactId=myBlock1</tt></p>
    
--- <p>The simplest way to start your own Cocoon 2.2 based project is using the
--- provided Maven 2 archetypes creating a skeleton for your project.</p>
+++ <p>Move into the myBlock1 directory and call</p>
    
--- <h1>Creating a web application project</h1>
+++ <pre>mvn install</pre>
    
--- <p>The cocoon webapp archetype creates a Maven 2 webapp project for you
--- containing</p>
+++ <p>from there. This installs the block into your local Maven repository.</p>
    
--- <ul>
--- <li>a skeleton web.xml</li>
--- <li>a cocoon.xconf</li>
--- </ul>
+++ <p>Looking at the filesystem, you should find following directory 
structure:</p>
    
--- <p>Make sure that you have Maven 2.0.4 or above installed and then enter
--- following command:</p>
+++ <pre>getting-started-app
+++  +-<tt>myCocoonWebapp
+++  |  +-pom.xml
+++  |  +-src
+++  |     +-[...]
+++  +-</tt><tt>myBlock1
+++     +-pom.xml
+++     +-src
+++        +-[...]
+++ </tt></pre>
    
--- <pre>mvn archetype:create \
---   -DarchetypeGroupId=org.apache.cocoon \
---   -DarchetypeArtifactId=cocoon-22-archetype-webapp \
---   -DarchetypeVersion=1.0.0-M1 \
---   -DgroupId=com.mycompany \
---   -DartifactId=myBlock
--- </pre>
+++ <p>As you can see,  the web application and the block are at the same 
level.</p>
    
--- <p class="note">once again 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-M1
--- -DgroupId=com.mycompany -DartifactId=myCocoonWebapp</tt></p>
+++ <h1>Using the block within the web application</h1>
    
--- <p>The next step is changing into the <tt>myBlock</tt> directory and 
calling</p>
+++ <p>So far the web application (<tt>myCocoonWebapp</tt>) doesn't have any
+++ information about the existense of the block (<tt>myBlock1</tt>). Change 
this by
+++ opening <tt>getting-started-app/myCocoonWebapp/pom.xml</tt>and add the 
block as
+++ dependency:</p>
    
--- <pre>mvn jetty:run</pre>
+++ <pre>&lt;project&gt;
+++   [...]
+++     &lt;dependencies&gt;
+++       &lt;dependency&gt;
+++         
&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;
+++       &lt;/dependency&gt;
+++     &lt;/dependencies&gt;
+++   [...]
+++ &lt;/project&gt;</pre>
    
--- <p>After that, you can point your browser to</p>
+++ <p>That's it. Now it's time to run the web application. Move into
+++ getting-started-app/myCocoonWebapp and call</p>
    
--- <pre>http://localhost:8888</pre>
+++ <pre>mvn jetty:run</pre>
    
--- <p>and you should get a success page.</p>
+++ <p>from there.<br/>
+++ Open your favorite web browser and call</p>
    
--- <h1>Creating a block project</h1>
+++ <pre>http://localhost:8888/myBlock1/</pre>
    
--- <p>The simplest way to start your own Cocoon 2.2 based project is using a 
Maven
--- 2 archetype, that creates a block skeleton for you. It only contains a</p>
+++ <p>That's it!</p>
    
--- <ul>
--- <li>minimal sitemap</li>
--- <li>a Flowscript that uses a Spring bean</li>
--- <li>a view pipeline that uses JXTemplate to display values form the 
bean</li>
--- </ul>
+++ <h1>Creating a parent pom</h1>
    
--- <p>Make sure that you have Maven 2.0.4 or above installed and then enter
--- following command:</p>
+++ <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>mvn archetype:create \
---   -DarchetypeGroupId=org.apache.cocoon \
---   -DarchetypeArtifactId=cocoon-22-archetype-block \
---   -DarchetypeVersion=1.0.0-M4 \
---   -DgroupId=com.mycompany \
---   -DartifactId=myBlock 
+++ <pre>&lt;project&gt;
+++   &lt;name&gt;Cocoon Getting Stared application 
[parent]application&lt;/name&gt;
+++   TBD
+++   &lt;modules&gt;
+++ <strong>    &lt;module&gt;myWebapp&lt;/module&gt;
+++     &lt;module&gt;myBlock1&lt;/module&gt;</strong>
+++   &lt;/modules&gt;
+++ &lt;/project&gt;
    </pre>
    
--- <p class="note">once again for copy and paste without line feeds:<br/>
--- <tt>mvn archetype:create -DarchetypeGroupId=org.apache.cocoon
--- -DarchetypeArtifactId=cocoon-22-archetype-block -DarchetypeVersion=1.0.0-M4
--- -DgroupId=com.mycompany -DartifactId=myBlock</tt></p>
+++ <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>The next step is changing into the <tt>myBlock</tt> directory and 
calling</p>
+++ <h1>Conclusion and further information</h1>
    
--- <pre>mvn jetty:run</pre>
+++ <p>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.<br/>
+++ 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:</p>
    
--- <p>After that, you can point your browser to</p>
+++ <ul>
+++ <li>Usage of the reloading classloader plugin<br/>
+++ 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.</li>
+++ <li>Your first XML pipeline<br/>
+++ Cocoon is 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.</li>
+++ <li>Adding a second block<br/>
+++ 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 (-&gt; skinning).</li>
+++ </ul>
    
--- <pre>http://localhost:8888</pre>
+++ <p>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
+++ <a href="http://maven.apache.org";>website</a>. Especially we recommend</p>
    
--- <p>and you should get a success page.</p>
+++ <ul>
+++ <li>
+++ <a 
href="http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html";>Maven
+++ in 5 minutes</a> and the</li>
+++ <li><a 
href="http://maven.apache.org/guides/getting-started/index.html";>Getting
+++ started guide</a></li>
+++ </ul>
    
    </body>
    </html>