Volume 8, Number 30 -- August 27, 2008

Jetty: An Efficient, Easy to Manage Alternative to WebSphere

Published: August 27, 2008

by Mike Brown

Note: The code accompanying this article is available for download here.

In the past couple of years, I have talked with colleagues and read articles about the complexity of WebSphere and the resources it uses. There are alternatives to WebSphere when you need a Servlet or JSP container. Apache Tomcat is probably one of the better known competitors to WebSphere. However, I would like to introduce you to another one that is smaller, easier to manage, and just plain works: Jetty.

Introduction to Jetty

Jetty is an open source Web server--implemented in Java--that provides Servlet and JSP support, among other things. Jetty has been around since 1995, has been incorporated in many products and tools such as the Eclipse IDE, and has a very active development community. You can get commercial support for Jetty from Webtide.

In addition to Servlet and JSP applications, Jetty can work with numerous other technologies, such as EJB3, Java Server Faces (JSF), AJAX, Google Web Toolkit (GWT) and others. There is also support for clustering, SSL, JNDI, ActiveMQ, transaction managers, and Web services.

The current version of Jetty, version 6.1.11 when this article was written, still runs on Java 1.4. This will be welcome news for those of us who may have older systems that do not support Java 1.5 yet. The upcoming version 7 will require Java 1.5.

While I won't go into it in this article, the Jetty Web server can be embedded inside a Java application. This means that you can deploy a Java application on the System i that provides a Web browser interface to manage and check the status of the running application.

Let's Get Started

Download the current release of Jetty 6.1 from the Jetty download page to your desktop computer. The download zip for Jetty 6.1 is only 17 MB, which includes Java source code, optional modules, and the entire Web site of documentation for Jetty. When we deploy this to the System i, we can exclude some of these directories and files. As a comparison, the IBM download page for WebSphere application Server Express, version 6, indicated that the download size is 543 MB.

Unzip the downloaded file to a directory of your choice. The contents of that install directory should look like Figure 1.

Figure 1. Jetty 6.1 Install Directory

That is it for installation! For those of you who are curious with how this compares to the installation of WebSphere v6, check out this article that describes the steps for installing WebSphere on the System i. The installation of Jetty on the System i will involve copying a subset of these directories and files to the IFS. You will probably want to set up some jobs on the job scheduler to start and stop the Jetty server so that it will always be available when you want it to be.

Create a Deployment Directory

Since you do not need the source code and documentation for deployment, create a new directory that to use for deployment to the System i. This new directory will contain a subset of directories and files from the install directory. The new directory should contain the directories and files shown in Figure 2.

Figure 2. Deployment Directory

While this configuration still includes example applications and optional libraries, at under 15 MB, I wouldn't worry about it too much! If you really wanted to reduce the amount of disk space required for the installation on the System i, you could remove some optional jar files in the lib directory. However, I do not recommend that. You may have a Web application that needs those features in the future. After playing around with the sample Web applications, you can safely delete all the files and directories in the webapps and contexts directories. This step will remove the sample Web applications.

Running and Stopping Jetty

Open a command shell/window on your computer and change your current working directory to the Jetty deployment directory you created above. To start the Jetty Web server, enter the command: java -jar start.jar. On some computers, you may also be able to run Jetty by double-clicking on the start.jar file. Jetty will write logging information to the standard output (the command window usually) by default. When Jetty has completed the initialization process, you will see the following message: INFO: Started SelectChannelConnector@ Jetty uses Apache log4j to handle logging for the application. You will want to eventually change the logging configuration to write to a file instead of standard output. The logging configuration file, log4j.properties, is found in the resources directory.

The default configuration tells Jetty to use port 8080 for HTTP requests. So, let's fire up a Web browser and see what we get. Enter the URL http://localhost:8080 into your favorite Web browser and you should see a page like that in Figure 3. Try out some of the links to test the installation, if you wish. None of them are terribly exciting, but they do demonstrate that Jetty is a functional Web server and a Servlet/JSP container.

Figure 3. Jetty's Test Web Application

To stop the Jetty Web server, type CONTROL-C in the command window. This obviously is not a good approach for production use and Jetty provides a better alternative. Using additional command line arguments when Jetty is started, you can instruct Jetty to listen for a specific stop command. Here is an example command to start Jetty so that it listens for a stop command on port 9090 and requires a password of i5Rules:

java -DSTOP.PORT=9090 -DSTOP.KEY=i5Rules -jar start.jar

The command to stop Jetty given the above would be:

java -DSTOP.PORT=9090 -DSTOP.KEY=i5Rules -jar start.jar --stop

The commands above could easily be added to the job scheduler to start and stop Jetty at specific times. I would suggest creating scripts, named start.sh and stop.sh, with the appropriate commands above in your deployment directory. If you plan to use these scripts in the job scheduler, you will need to add a line before the java command that changes the current working directory to the location you will install Jetty. This will allow the java command to find the necessary dependent jar files.

Deploying Jetty to the System i

Now that you are familiar with starting and stopping Jetty, you need to get it installed on the System i. If you want to delete the demonstration applications that came with Jetty, you will need to delete all the files and directories in both the CONTEXT and WEBAPPS directories in the deployment directory. Create a new directory in the IFS for Jetty. I recommend that it be installed in /QOpenSys/jetty6.1.11. Using your favorite method (iSeries Navigator, FTP, etc.), copy all the files and directories in the Jetty deployment directory to /QOpenSys/jetty6.1.11.

Once you have copied the files to the System i, start the Web server with the start.sh script that you created or enter the command manually in Qshell. Unless you are using the new 32-bit Java 1.5 environment, you will likely see a bunch of "Attaching Java program..." lines scrolling on the screen. If you have used Java before on the System i, you know this only happens the first time you run a Java application. When you run the start command the next time, the Web server will start much faster. Now that Jetty is running on your System i, test it out with the URL above (substituting the name or IP address of your System i).

Sample Application

I have created a very small project with NetBeans IDE that is available here. The project includes a very simple JavaServer Pages file and a very simple Java Servlet. These should help you get started writing your own. In addition, there is a Web application archive (WAR) file that contains the compiled version of the JSP and servlet. You can use this WAR file to practice deploying a new application to Jetty and configuring the Web server.

Deploying Your Application

The standard way to deploy a Java Web application is to create a WAR file, which NetBeans IDE does automatically for you when it compiles your source code and runs the project. We need to copy the WAR file to the WEBAPPS directory contained in the location you installed Jetty. If you followed my suggestion above, this would be /QOpenSys/jetty6.1.11/webapps.

By default, Jetty is configured to monitor a specific directory for additions or changes to enable you to deploy or redeploy a Web application while Jetty is running. To make use of this feature, you need to create a small XML file and place it in /QOpenSys/jetty6.1.11/contexts. For this tutorial, I created demo.xml with the following contents:

<?xml version="1.0"  encoding="ISO-8859-1"?>

<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"

<!-- ==================================================================

Configure and deploy the demo web application in $(jetty.home)/webapps/demo

===================================================================== -->

<Configure class="org.mortbay.jetty.webapp.WebAppContext">

  <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

  <!-- Required minimal context configuration :                        -->

  <!--  + contextPath                                                  -->

  <!--  + war OR resourceBase                                          -->

  <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

  <Set name="contextPath">/demo</Set>

  <Set name="war"><SystemProperty name="jetty.home" 

</ Configure>

The contextPath value will define the Web application context. So you access the application using a URL like the following: http://server:8080/demo. Once you place demo.xml in the contexts directory, you can test it out.

This is the first time that I've discussed configuration of Jetty. That is because the default configuration of Jetty serves well for simple installations. If you need to change the configuration or use some advanced features, you can do so by editing XML files in the ETC directory where Jetty is installed. The resources section has a link to Jetty's WIKI for configuration. I recommend making a copy of the XML files before you edit them so you can easily revert back if you need to.

You're Up and Running!

While I don't have first-hand experience installing and configuring WebSphere, I'm going to guess that it is a little more involved than what is explained here. Making configuration changes involves using a text editor to change readable and well commented XML files. So start experimenting with running Java Web applications today without worrying about how you will manage the server or about the resources being consumed on your System i.

Mike Brown is the founder of comIT, LLC, a consulting company that provides architecture, project management, and development services. Mike's experience ranges from compiler development to Department of Defense contract work to commercial IT systems. Send your questions or comments for Mike to Ted Holt via the IT Jungle Contact page.


Installing WebSphere Application Server 6.0

Configuring Jetty

                     Post this story to del.icio.us
               Post this story to Digg
    Post this story to Slashdot

Sponsored By

It doesn't take 'rocket science' to integrate
remote data into your IBM i applications.

Finally, a product that provides easy and full
SQL access to remote databases from System i.
Remote Database Connect gives you easy access to
remote data from your RPG, Cobol or CL programs.
Access MySQL, Microsoft SQL Server, Oracle,
Postgre and DB2 and more.....

Share real time data across platforms NOW!

Use RDB Connect with DBU remote plugin for even more power!
Download a trial or watch our webinars.


Senior Technical Editor: Ted Holt
Technical Editor: Joe Hertvik
Contributing Technical Editors: Edwin Earley, Brian Kelly, Michael Sansoterra
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.

Sponsored Links

Infinite Software:  Migrate System i RPG or COBOL apps to Linux, Windows or Unix
COMMON:  Join us at the Focus 2008 workshop conference, October 5 - 8, in San Francisco, California
Computer Measurement Group:  CMG '08 International Conference, December 7-12, Las Vegas


IT Jungle Store Top Book Picks

Easy Steps to Internet Programming for AS/400, iSeries, and System i: List Price, $49.95
Getting Started with PHP for i5/OS: List Price, $59.95
The System i RPG & RPG IV Tutorial and Lab Exercises: List Price, $59.95
The System i Pocket RPG & RPG IV Guide: List Price, $69.95
The iSeries Pocket Database Guide: List Price, $59.00
The iSeries Pocket Developers' Guide: List Price, $59.00
The iSeries Pocket SQL Guide: List Price, $59.00
The iSeries Pocket Query Guide: List Price, $49.00
The iSeries Pocket WebFacing Primer: List Price, $39.00
Migrating to WebSphere Express for iSeries: List Price, $49.00
iSeries Express Web Implementer's Guide: List Price, $59.00
Getting Started with WebSphere Development Studio for iSeries: List Price, $79.95
Getting Started With WebSphere Development Studio Client for iSeries: List Price, $89.00
Getting Started with WebSphere Express for iSeries: List Price, $49.00
WebFacing Application Design and Development Guide: List Price, $55.00
Can the AS/400 Survive IBM?: List Price, $49.00
The All-Everything Machine: List Price, $29.95
Chip Wars: List Price, $29.95

The Four Hundred
PowerTech Acquired by Help/Systems, Private Equity Firm

JDA Ponies Up $346 Million to Buy i2 Technologies

SMBs Are Sensibly More Concerned with Biz than Tech

As I See It: Lessons from Robben Island

Big Blue Launches XIV Clustered Storage Arrays

The Linux Beacon
Why Blade Servers Still Don't Cut It, and How They Might

Intel Keeps Both Arms Swinging with Xeons, Jabs with Itanium

Microsoft Ponies Up Another $100 Million for Novell Linux

Mad Dog 21/21: Newtonian Economics

Two More Xeon-Based Galaxy Servers from Sun

Four Hundred Stuff
A Bumblebee for BI--Now That's Just 'Smart'

Curbstone Gains PCI Compliance for i OS Payment System

Life is Easy for iPhone Apps on the Morph Labs Cloud

WebClient for CA Plex 1.4 Now Available

Avnet to Resell VDoc Content Management Suite in U.S.

Big Iron
For Some Customers, the Mainframe Is Green

Top Mainframe Stories From Around the Web

Chats, Webinars, Seminars, Shows, and Other Happenings

System i PTF Guide
August 23, 2008: Volume 10, Number 34

August 16, 2008: Volume 10, Number 33

August 9, 2008: Volume 10, Number 32

August 2, 2008: Volume 10, Number 31

July 26, 2008: Volume 10, Number 30

July 19, 2008: Volume 10, Number 29

The Windows Observer
Windows 7 Means Windows Server 2008 R2, Microsoft Reveals

Free Range Apps Can Roam the Farm, Microsoft Says

It's Black Tuesday for Microsoft, with 26 Flaws Patched

Why Blade Servers Still Don't Cut It, and How They Might

SQL Server 2008 Goes RTM

The Unix Guardian
What the Heck Is the Midrange, Anyway?

Overseas and Notebook Sales Offset Printer Declines for HP in Q3

Two More Xeon-Based Galaxy Servers from Sun

Mad Dog 21/21: Newtonian Economics

Intel's Nehalems to Star at IDF, AMD Pitches Shanghai

Four Hundred Monitor
Four Hundred Monitor's
Full iSeries Events Calendar


ProData Computer Services
System i Developer

Printer Friendly Version

Automatic or Static Storage?

Jetty: An Efficient, Easy to Manage Alternative to WebSphere

Admin Alert: Giving Auditors What They Want

Four Hundred Guru


From the IT Jungle Forums
MQ Help Desired

Printing TCP/IP Details into a Spoolfile

IFF ACTIVE Equivalent in CL

Capture Sort File and Copy to Database File

SNMP Traps on i5OS

Java Messages

Subscription Information:
You can unsubscribe, change your email address, or sign up for any of IT Jungle's free e-newsletters through our Web site at http://www.itjungle.com/sub/subscribe.html.

Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.
Guild Companies, Inc., 50 Park Terrace East, Suite 8F, New York, NY 10034

Privacy Statement