home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book HomeJava and XML, 2nd EditionSearch this book

10.2. Installation

In other chapters, installation instructions generally involved pointing you at a web site where you could obtain a distribution of the software and letting you add the included jar file to your classpath. Installing a framework such as Cocoon is not quite as simple, and the procedures are documented here. Additionally, Cocoon has instructions online for various other servlet engines; check these out at http://xml.apache.org/cocoon/install.html.

10.2.2. Configuring the Servlet Engine

Once you have built Cocoon, configure your servlet engine to use Cocoon and tell it which requests Cocoon should handle. I'll look at setting up Cocoon to work with the Jakarta Tomcat servlet engine here; as this is the reference implementation for the Java Servlet API (Version 2.2), you should be able to mimic these steps for your own servlet engine if you are not using the Tomcat implementation.

The first step is to copy all of the libraries needed for Cocoon at runtime into Tomcat's library directory. This is located at TOMCAT_HOME/lib, where TOMCAT_HOME is the directory of your Tomcat installation. On my Windows machine, this is c:\java\jakarta-tomcat, and on Linux it's /usr/local/jakarta-tomcat. However, this does not mean simply copy everything in Cocoon's lib/ directory over (unless you want to); the required jar files needed at runtime are:

  • bsfengines.jar (Bean Scripting Framework)

  • bsf.jar (Bean Scripting Framework)

  • fop_0_15_0.jar (FOP)

  • sax-bugfix.jar (SAX fixes to error handling)

  • turbine-pool.jar (Turbine)

  • w3c.jar (W3C)

  • xalan_1_2_D02.jar (Xalan)

  • xerces_1_2.jar (Xerces)

Additionally, copy Cocoon's bin/cocoon.jar file into this same directory (TOMCAT_HOME/lib). At that point, you'll have all the libraries needed to run Cocoon.

The latest versions of Tomcat (I'm using 3.2.1) automatically load all libraries in the Tomcat lib/ directory, which means you don't have to mess with the classpath. If you are using a servlet engine that doesn't support this automatic loading, add each jar to the servlet engine's classpath.

Once the required libraries are in place, let the servlet engine know which context to run Cocoon under. This essentially tells the servlet engine where to look for files requested through the Cocoon engine. This is handled by modifying the server.xml file, located in Tomcat's conf/ directory. Add the following directive in at the end of the file, within the ContextManager element:

<Server>
  <!-- Other Server elements -->

  <ContextManager>
    <!-- Other Context directives -->

    <Context path="/cocoon" 
             docBase="webapps/cocoon" 
             debug="0"
             reloadable="true" >
    </Context>
  </ContextManager>
</Server>

In other words, requests based on the URI /cocoon (such as /cocoon/index.xml) should be mapped to the context within the specified directory (webapps/cocoon). Of course, you'll need to create the directories for the context you've just defined. So add a cocoon and cocoon/WEB-INF directory to Tomcat's webapps directory. You should have a directory structure similar to Figure 10-1.

Figure 10-1

Figure 10-1. Cocoon context directory structure

With this setup, you'll need to copy a few files from the Cocoon distribution into the context. Copy Cocoon's conf/cocoon.properties and src/WEB-INF/web.xml files into the TOMCAT_HOME/webapps/cocoon/WEB-INF/ directory. Once this is in place, you only need to modify the web.xml file that you just copied. Change the reference in it to point to the cocoon.properties file you just copied over:

<web-app>
 <servlet>
  <servlet-name>org.apache.cocoon.Cocoon</servlet-name>
  <servlet-class>org.apache.cocoon.Cocoon</servlet-class>
  <init-param>
   <param-name>properties</param-name>
   <param-value>WEB-INF/cocoon.properties</param-value>
  </init-param>
 </servlet>
 
 <servlet-mapping>
  <servlet-name>org.apache.cocoon.Cocoon</servlet-name>
  <url-pattern>*.xml</url-pattern>
 </servlet-mapping>
</web-app>

At this point, you have one last, rather annoying, step to perform. Tomcat automatically loads all the jar files in its lib/ directory, and it does it alphabetically, according to the name of the jar file. The problem is that Cocoon requires a DOM Level 2 implementation (such as the one in Xerces, included with Cocoon in xerces_1_2.jar); however, Tomcat uses a DOM Level 1 implementation, included in parser.jar. Of course, because of the alphabetical listing, parser.jar gets loaded before xerces_1_2.jar, and Cocoon bombs out. To solve this, rename your parser.jar archive something that will get loaded after Xerces; I used z_parser.jar. This step ensures that the classes are still available to Tomcat, but that the DOM Level 2 classes are loaded first and used by Cocoon.

Once you complete these steps, test Cocoon by loading up the Cocoon information URI, which reports details about Cocoon's installation. Access http://[hostname:port]/cocoon/Cocoon.xml. In a default installation, this would be http://localhost:8080/cocoon/Cocoon.xml. Your browser should give you results similar to those in Figure 10-2.

Figure 10-2

Figure 10-2. Checking the Cocoon installation

Once this is set up, you're ready to put some real content into place. With the setup you already have, all requests that end in .xml and are within the defined Cocoon context will be handled by the Cocoon servlet.



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.