ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

What Is Geronimo?
Pages: 1, 2, 3

Sample Application

For an introductory article like this, we'll create a simple web application and deploy it on Geronimo. Please make sure that the following environment variables are set correctly.

Environment variable Purpose
JAVA_HOME Indicates the base directory of your standard Java SE installation.
GERONIMO_HOME Set to the root directory of your Geronimo installation.
ANT_HOME Set to the root directory of your Ant installation.
GERONIMO_DEV Indicates the base directory of application development space.
PATH Ensure that ANT_HOME/bin is in your PATH.

Within GERONIMO_DEV, create the following directories:

  • etc: All deployment plans are kept inside this directory.
  • src: This directory is used for placing any servlets and other Java source files.
  • web: All public JSP documents are placed inside this directory.

Deployment Plans

We'll need two deployment plans, namely web.xml and geronimo-web.xml. Before we dive into these, I'll clarify their differences. The following table will help differentiate between the two deployment plans and their roles.

Deployment Plan Type Location Purpose
web.xml Standard Java EE web deployment descriptor This must be stored as part of the WAR file under the WEB-INF subdirectory. Used for specifying declarative security, configuring error and welcome pages, servlet declaration and mapping, filter definition and mapping, configuring initialization parameters, registering listener classes, etc.
geronimo-web.xml Geronimo-specific deployment plan Under the private WEB-INF subdirectory. The geronimo-web.xml file defines Geronimo-specific parts such as resource references and security mapping configuration.

Code Your First Geronimo App

We'll begin by creating a simple JSP page to greet the user and display the current date and time. Create hello.jsp as shown below and place it in the GERONIMO_DEV/web directory:

<jsp:useBean id="currentdate"
    class="java.util.Date" />
<title>Geronimo JSP App</title>
<h3>Hello world from Geronimo!! on

Next, create the following two deployment plans and place them inside the GERONIMO_DEV/etc directory. The first deployment plan, web.xml, is the standard Java EE deployment descriptor as shown here:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"

    <display-name> Hello JSP Web App
    <description>First Geronimo App

The following code snippet shows the Geronimo-specific deployment plan, geronimo-web.xml:

<?xml version="1.0" encoding="UTF-8"?>


The configId attribute specifies the name of our application, com/onjava/safari/myApp. Next, we set up the context (/myApp), which is the directory where our application is placed once deployed to Geronimo.

Build the App

Next, we'll do an incremental build with Ant. We need an Ant build file (build.xml), placed in GERONIMO_DEV. The build.xml is a well-formatted XML file that describes the build process of our application as shown below:

<project name="GeronimoApp" default="war"

  <property environment="env"/>

 <path id="cp">
      <pathelement path="${java.class.path}"/>
      <fileset dir="${env.GERONIMO_HOME}/
        <include name="*.jar"/>

 <target name="prepare">
    <mkdir dir="dist"/>
    <mkdir dir="classes"/>
    <mkdir dir="build"/>

     <fileset dir="classes"

    <mkdir dir="build/WEB-INF"/>
    <mkdir dir="build/WEB-INF/lib"/>

    <copy file="etc/web.xml" todir="build/WEB-INF"/>
    <copy file="etc/geronimo-web.xml"
    todir="build/WEB-INF" />

    <copy todir="build">
      <fileset dir="web"/>


<target name="compile" depends="prepare">
    <javac srcdir="src" destdir="classes"
    debug="on" deprecation="off">
      <classpath refid="cp"/>

<target name="war" depends="compile">
   <war destfile="dist/safari.war"
    <classes dir="classes" />
      <fileset dir="build">
        <exclude name="WEB-INF/web.xml"/>


Following is the output we'll get after running the Ant script:


Buildfile: build.xml

  [mkdir] Created dir: D:\gdev\dist
  [mkdir] Created dir: D:\gdev\classes
  [mkdir] Created dir: D:\gdev\build
  [mkdir] Created dir: D:\gdev\build\WEB-INF
  [mkdir] Created dir: D:\gdev\build\WEB-INF\lib
   [copy] Copying 1 file to D:\gdev\build\WEB-INF
   [copy] Copying 1 file to D:\gdev\build\WEB-INF
   [copy] Copying 1 file to D:\gdev\build


      [war] Building war: D:\gdev\dist\safari.war

Total time: 3 seconds

This creates a .war file (placed inside the /dist directory), which will be deployed inside the Tomcat container shipped with Geronimo app server.

Pages: 1, 2, 3

Next Pagearrow