THL Toolbox > Developers' Zone > Web Development > Setting Up Cocoon 2.2
Setting Up Cocoon 2.2 as a Tomcat Servlet
Contributor(s): Than Grove
To transform XML content into web pages, THL uses Apache Cocoon as a servlet within Tomcat. Initially, we used Cocoon 2.1.11 built into a servlet by members of the UVa library staff. In April of 2012, it was decided we should begin the migration to Cocoon 2.2, which represents a major shift in architecture and deployment. Cocoon 2.2 is fully modular, its functionality having been segregated into blocks. Furthermore, the Apache Maven program is used, instead of Ant, to build a project from Cocoon. Once the Cocoon WAR file has been built, it is easy to install but the building of the .war file is more complicated issue. To document this process, the steps taken to create the cocoon22.war file presently installed on THL's Development are detailed below.
Creating the Cocoon 2.2 War file
- Installed Maven 3.0.4
- Downloaded Maven and unpacked it to /etc/maven-3.0.4
- Set your shell path to recognize Maven by doing:
- [sds-deployer@dev1 cocoonCore?]$ export M2_HOME=/etc/maven-3.0.4/
- [sds-deployer@dev1 cocoonCore?]$ export M2=$M2_HOME/bin
- [sds-deployer@dev1 cocoonCore?]$ export PATH=$M2:$PATH
- Check to make sure it is installed by entering "mvn --version"
- At /usr/local/projects/thlib-cocoon/cocoon22/ executed the command "mvn archetype:generate -DarchetypeCatalog=http://cocoon.apache.org"
- After downloading many files, it asks to choose one of three options. Chose 2 "Create a cocoon block containing some small samples" and set the following parameters:
- Group ID: org.thlib
- Artifact ID: cocoonCore
- Version: 1.0.0
- Package: org.thlib.cocoonCore
- Edit the file cocoonCore/pom.xml by running "vi pom.xml" and make the following changes:
- Add the dependency for FOP at the end of the group of <dependencies>. This code is below in Code Snipets > Dependencies > FOP
- change the line "<Cocoon-Block-Name>${pom.artifactId}</Cocoon-Block-Name>" to "<Cocoon-Block-Name>${project.artifactId}</Cocoon-Block-Name>"
- Save with :x
- Navigate back to home folder /usr/local/projects/thlib-cocoon/cocoon22 and run the command again: "mvn archetype:generate -DarchetypeCatalog=http://cocoon.apache.org" but pick option 3 and enter the following params entered upon request:
- Group ID: org.thlib
- Artifact ID: cocoonWebapp
- Version: 1.0.0
- Package: org.thlib.cocoonWebapp
- Edit the file cocoonWebapp/pom.xml with vi and make the following changes:
- Comment out the Jetty <plugin> definition
- Add the plugin definition for either Tomcat 6 or 7, depending on which you are using. See below in Code Snippets > Plugin Definitions.
- Add a dependency to the org.thlib.cocoonCore block by adding the code found in This code is below in Code Snipets > Dependencies > Cocoon Core.
- Save the file with :x
- Change folder to /thlib-cocoon/cocoon22/cocoonCore/
- Run "mvn install"
- Change back to /thlib-cocoon/cocoon22/cocoonWebapp/
- Run "mvn package"
- cp cocoonWebapp-1.0.0.war to /thlib-cocoon/cocoon22/shared/
Adding Tomcat Manager To Tomcat6 Install
On Dev1 thlib.org, Tomcat manager was not installed. So, I installed that by:
- Logging onto Dev1 with secureCRT
- sudo su root (my password)
- cd /usr/share/tomcat (though not necessary I think)
- Run "sudo yum install tomcat6-admin-webapps"
- cd /etc/tomcat6 and vi tomcat-users.xml, added manager-gui role and "deployer" user with the same password as on previous dev.
- Restarted tomcat by doing "systemctl stop tomcat6.service" and "systemctl start tomcat6.service" as I wasn't sure if "systemctl restart tomcat6.service" was working right.
- Then I could logon to manager.
Test Of Cocoon Webapp
Tried installing webapp using the manager to see if demo would work before configuring for THL:
- Placed war from cocoon22/cocoonWebapp/target in /usr/local/projects/thlib-cocoon/current and created the Tomcal web app context file at /usr/local/projects/thlib-cocoon/shared/thlib-cocoon.xml
- Went to http://dev.thlib.org:8080/manager/html
- At the bottom of the list entered:
- Context Path: /cocoon
- XML Configuration file URL: /usr/local/projects/thlib-cocoon/current/cocoonWebapp-1.0.0.war
- And pressed deploy button but it was not working. Apparently there is a bug (see http://www.coderanch.com/t/524388/Tomcat/Tomcat-cannot-deploy-application-access and https://issues.apache.org/bugzilla/show_bug.cgi?id=51147) You have to edit the html page in browser (in Chrome using ctrl+shift+I and change the form method from "get" to "post").
Increasing Memory for Tomcat
Turns out the memory setting for Tomcat was not boosted like it is on old Dev, Staging and Production. So edited the /etc/tomcat6/tomcat6.conf file with vi and added CATALINA_OPTS variable in the following context:
CATALINA_TMPDIR="/var/cache/tomcat6/temp" CATALINA_OPTS="-server -Xmx3000m -Xms3000m -XX:+UseParallelGC -XX:+AggressiveOpts -XX:PermSize=256m -XX:MaxPermSize=512m -Djava.awt.headless=true"
Then restarted Tomcat
Configuration for Site
Test worked but need to make certain modifications to get it to work in THL.
- cd /usr/local/projects/thlib-cocoon/cocoon22/cocoonCore/src/main/resources/META-INF/cocoon/spring/
- vi block-servlet-service.xml
- Change the line for <servlet:context …> to "<servlet:context mount-path="" context-path="file:///usr/local/projects/thlib-texts/current/cocoon/"/>"
- This means that the path to invoke cocoon (mount-path) would be whatever is declared in Context Path when deployed in Context (in this case /cocoon or the full url of http://dev.thlib.org:8080/cocoon) and the root for the application (context-path) is the location of the THL XML Texts SVN repository on Dev1.
- cd /usr/local/projects/thlib-cocoon/cocoon22/cocoonCore/
- Run "mvn install"
- cd /usr/local/projects/thlib-cocoon/cocoon22/cocoonWebapp/
- Run "mvn package"
- Install as above.
Code Snippets
Dependencies
FOP
<!-- Added Dependecies -->
<!-- FOP (Added by ndg8f, 2012-05-02 -->
<dependency>
<groupId>org.apache.cocoon</groupId>
<artifactId>cocoon-fop-impl</artifactId>
<version>1.0.0</version>
</dependency>Cocoon Core
<dependencies>
<dependency>
<groupId>org.thlib</groupId>
<artifactId>cocoonCore</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>Plugin Definitions
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<version>2.0-beta-1</version>
</plugin>or
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0-SNAPSHOT</version>
</plugin>