Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This article covers the migration one of the most fundamental aspects of J2EE; : servlets and JSPs. The sample application used for this migration exercise is College Fest which just contains servlets and JSPs for handling the flow of control. The College Fest sample application does not use any database, for details on migrating JDBC applications refer to the JBoss to Geronimo - JDBC Migration (Unverified on 2.1) article.

...

This article is organized in the following sections:

Servlets and JSPs implementation analysis
Anchor
implementation
implementation

Servlets and JSPs implementations may vary from one application server to another. The purpose of this section is to provide servlets and JSPs specific feature-to-feature comparison between JBoss and Apache Geronimo so you can clearly identify the differences and plan accordingly before migration.

...

Apache Geronimo currently supports two Web containers: Jetty and Tomcat.

Jetty

Jetty is a 100% Java HTTP Server and Servlet Container. This means that you do not need to configure and run a separate Web server in order to use servlets and JSPs to generate dynamic content. Jetty is a fully featured Web server for static and dynamic content.

...

Each Jetty connector is a GBean, so the process of configuring a Jetty connector involves configuring a GBean.

Apache Tomcat

Apache Tomcat is the servlet container that is used in the official Reference Implementation for the Java Servlet and JavaServer Pages technologies.

http://java.sun.com/products/servlet
http://java.sun.com/products/jsp

The differences

JBoss v4 supports only Tomcat 5.5, which is the default Web container. The embedded Tomcat service is the expanded SAR jbossweb-tomcat55.sar in the deploy directory. The web.xml file that provides a default configuration set for Web application is also found in this exapanded SAR directory structure.

...

The Geronimo Web application deployment plan is geronimo-web.xml. The corresponding deployment descriptor in Jboss is jboss-web.xml. For further details on Geronimo deployment architecture you may refer to the Understand Geronimo's deployment architecture article.

Another difference with servlets and JSPs lies in the way the Web application is deployed. In Geronimo, the application package (ear, war, rar or jar) is deployed using the deployment tool deployer.jar located in the <geronimo_home>/bin directory.

Anchor
deploymentTool
deploymentTool

The deployer.jar deploys the application module based on the information provided in the deployment plan (if a plan is provided) to the Geronimo server. The server then saves the metadata to a configuration store and the executables to a binary repository. The following figure illustrates the behavior of the deployment tool.

...

In JBoss, a Web application is deployed by simply copying the application package (ear, war, rar or jar) into the <jboss_home>/server/<your_server_name>/deploy directory from where the server detects its presence and deploys it accordingly.

...

Feature

JBoss v4

Apache Geronimo

Deployment descriptor/plan

jboss.xml

geronimo-web.xml

Method of deployment

Copy the package (ear, war, rar or jar) to the deploy folder of the JBoss server <jboss_home>/server/<your_server_name>/deploy

Deployer tool available in server's bin directory
<geronimo_home>/bin. Deployment is also available through the Introducing Geronimo Administration Console administration console. A third option is Hot deploymentDeployment, which would be the equivalent to JBoss functionality.

Web container

Apache Tomcat 5.5

Jetty and/or Apache Tomcat

Back to Top

Sample application
Anchor
sampleApp
sampleApp

The College Fest application handles registration for events at a college festival. This is a very simple application that does not use any type of database. The College Fest application has the following four pages:

...

The user access the Welcome page and enters user name and college. From there the user can see the list of available events. The user can access the details for each Event by clicking them from the list. From the Event details page the user can register for that particular event.

Application classes and JSP pages

The College Fest sample application consists of the following two servlets:

...

  • welcome.jsp - Displays the events list to the user so that s/he can choose on what event to register.
  • dc.jsp - Displays the details for the Dumb Charades event.
  • pp.jsp - Displays the details for the Pot Potpourri event.
  • wtgw.jsp - Displays the details for the What's The Good Word event.
  • gq.jsp - Displays the details for the General Quiz event.
  • team_reg.jsp - Handles the user registration for one event.

Tools used

The tools used for developing and building the College Fest sample application are:

Eclipse

The Eclipse IDE was used for development of the sample application. This is a very powerful and popular open source development tool. Integration plug-ins are available for both JBoss and Geronimo. Eclipse can be downloaded from the following URL:
http://www.eclipse.org

Apache Ant

Ant is a pure Java build tool. It is used for building the war files for the College Fest application. Ant can be downloaded from the following URL:
http://ant.apache.org

Back to Top

The JBoss environment
Anchor
JBoss
JBoss

This section shows you how and where the sample JBoss reference environment was installed so you can map this scenario to your own implementation.

Detailed instructions for installing, configuring, and managing JBoss are provided in the product documentation. Check the product Web site for the most updated documents.

...

  1. Download and install JBoss v4 as explained in the product documentation guides. From now on the installation directory will be referred as <jboss_home>.
  2. Create a copy of the default JBoss v4 application server. Copy recursively <jboss_home>\server\default to <jboss_home>\server\<your_server_name>.
  3. Start the new server by running the run.sh -c <your_server_name> command from the <jboss_home>\bin directory.
  4. Once the server is started, you can verify that it is running by opening a Web browser and pointing it to this URL: http://localhost:8080. You should see the JBoss Welcome window and be able to access the JBoss console.
  5. Once the application server is up and running, the next step is to install and configure all the remaining prerequisite software required by the sample application. This step is described in the following section.

...

Apache Ant can be downloaded from the following URL:

http://ant.apache.org

Build the sample application

The College Fest application included with this article provides an Ant script that you will use in order to build the application. Download the College Fest application from the following link:

...

From a command line, still within the college_fest directory type the following command:

ant -f jboss-build.xml clean deploy

With this command, ant will use the targets defined in the jboss-build.xml file to build the College Fest application and deploy it to the JBoss server. Take a special look at <target name="deploy" ...>, here is where the jboss-build.xml tell ant where to deploy the WAR file. The following example shows the definitions in the jboss-build.xml file.

Code Block
xml
xml
borderStylesolid
titlejboss-build.xml
<?xml version="1.0"?>
<!-- build file for building a war -->

<project name="build" default="war" basedir=".">

    <property file="build.properties"/>
    <property name="src.dir" value="src"/>
    <property name="dest.dir" value="bin"/>
    
    <target name="clean" description="Delete all generated files">
        <echo message="Deleting bin directory" />
        <delete dir="bin" />
    </target>

	<target name="compile">
		<mkdir dir="${dest.dir}"/>
		<javac srcdir="${src.dir}" destdir="${dest.dir}">
			<classpath path="${java.home}/lib/tools.jar"/>
			<classpath path="${j2ee.home}/lib/j2ee.jar"/>
		</javac>
	</target>

	<target name="war" depends="compile">
		<war destfile="college_fest.war" webxml="WEB-INF/web.xml">
			<zipfileset dir="jsp" prefix="jsp"/>   	 
			<zipfileset dir="pix" prefix="pix"/>   	 
			<classes dir="${dest.dir}"/>   
                        <webinf dir="WEB-INF" />
		</war>
	</target>

	<target name="deploy" depends="war">
		<copy file="college_fest.war" todir="${jboss.server}/deploy"/>
	</target>

	<target name="undeploy">
		<delete file="${jboss.server}/deploy/college_fest.war"/>
    </target>
</project>

The war created by the ant build contains a JBoss specific deployment descriptor, the jboss-web.xml file in the WEB-INF directory of the WAR is shown in the following example.

Code Block
xml
xml
borderStylesolid
titleJBoss deployment descriptor
<?xml version="1.0" encoding="UTF-8"?>

<jboss-web>

    <context-root>college_fest</context-root>
    <context-priority-classloader>
      false
    </context-priority-classloader>
</jboss-web>

Back to Top

Deploy the sample application

The previous step showed how to deploy the application at build time by specifying a customized jboss-build.xml file. If you used the default build.xml file at build time you still need to deploy the College Fest application manually. To deploy the College Fest application in JBoss, copy the college_fest.war file you just built with Ant to the following directory:

<jboss_home>\server\<your_server_name>\deploy

If JBoss is already started, it will automatically deploy and start the application; otherwise, the application will be deployed and started at the next startup.

Back to Top

Testing the application
Anchor
test
test

To test the application, open a Web browser and access the following URL:

...

You should see the Welcome screen where you can login with your name and college. When you enter your name a college and click Submit you will see a message at the end on the page stating your name with a link to "Click here" to enter the site. Browse the site and check the options, at this point the College Fest application is configured and running.

Back to Top

The Geronimo environment
Anchor
Geronimo
Geronimo

Download and install Geronimo from the following URL:

...

Warning
titleTCP/IP ports conflict

If you are planning to run JBoss and Geronimo on the same machine consider to change the default service ports on, at least, one of these servers.

Back to Top

Step-by-step migration
Anchor
migration
migration

In order to migrate the College Fest application to Geronimo you need to replace the jboss-web.xml file with a geronimo-web.xml file which is the Geronimo specific descriptor file. The geronimo-web.xml file is located in the WEB-INF directory withing the college_fest directory structure. The Geronimo deployment plan geronimo-web.xml is illustrated in the following example.

...

Earlier in this article it was discussed the behavior of the deployment tool. During the deployment process, you provide to the deployment tool the application module and a deployment plan. The College Fest sample application is so simple that you may choose not to provide any deployment plan and let Geronimo do the deployment with a default set of values (a default context root for example).

...

To delete the generated files for a clean build run ant clean followed by an ant.

Back to Top

Deploy the migrated sample application

To deploy the migrated College Fest application, make sure the Geronimo server is up and running.

From a command line, change directory to <geronimo_home>/bin and type the following command:

deploy --user system --password manager deploy <college_fest_home>/college_fest.war

Once the application is deployed, open a Web browser and access the following URL:

...

Repeat the steps you did when Testing the application on the JBoss environment.

Back to Top

Summary
Anchor
summary
summary

This article has shown you how to migrate a simple Servlet and JSPs application, from JBoss to the Apache Geronimo application server. You followed step-by-step instructions to build the application, deploy and run it, and then migrate it to the Geronimo environment.

...