Tags:

Tomcat 5.5 tutorial

Wouldn't it be great if the web application that you wrote to run on a server could be made to run on a regular desktop computer with minimal effort on the user's side? You start thinking about all the obstacles you have to overcome: First of all, the computer may not have JDK or JRE installed. You also need Tomcat to run your servlets. And finally, you need to direct the user to open a browser and navigate to your application's start page. In this article, I am going to show you how you can package your application together with all required components (JRE , Tomcat, and a few other free/open-source components) that the user can just unzip to his/her computer and then run by clicking on an executable file, no batch file required. The application size is small enough to fit on a portable USB drive, so you can even run your program without installing it on a computer! If your application requires a database, no problem - you can embed a pure Java database into your application.

Tomcat: The Definitive Guide is a great book about the most commonly used open-source servlet/JSP container. Tomcat is the official Reference Implementation for the Java Servlet and JavaServer Pages technologies. Tomcat is really powerful and flexible, but you really need a good book to figure out how to integrate Tomcat with Apache, how to set load-balancers, clustering, etc on all of the major platforms, including Windows, Solaris, Linux, and Mac OS X.

This is where Tomcat: The Definitive Guide comes in. This really well written book makes it easy to follow for the developer as well as non-developer admin. The book starts with an introduction of Tomcat (v4.0) where you learn how to stop/start the server, learn about the directory structure, and learn to modify the start/stop scripts as well as the configuration settings. I really like the treatment given to security, realms and JAAS in the second chapter with more details in the sixth chapter. Most books of this type will leave out security and this book deals with it in the second chapter. Kudos to the authors for that.

I also really like the chapter on performance tuning that deals with real-world applications. The chapter on integration with the Apache webserver is really well written. Most people that deploy Tomcat in production will want to put Apache webserver in front of Tomcat to serve up static content like html and images while letting Tomcat handle servlets and JSPs. Most of the documentation about this Apache httpd ? Tomcat integration on the Internet deals with v1.3 of Apache httpd. However, the book deals with Apache 2.0, which is another plus for the book.

I can go on and on - If you are using Tomcat, planning on using Tomcat or just want to learn more about the server, this book will provide you with all of the information to help harness Tomcat's power and wealth of features. I would highly recommend this book as a companion to any servlet/JSP programming book.

Following is a guide to installing and configuring Apache Tomcat 6 for use as a standalone Web server (for development) that supports servlets 2.5 and JSP 2.1. (Note: Apache Tomcat is sometimes referred to as "Jakarta Tomcat" since the Apache Java effort is known as "The Jakarta Project"). This Tomcat tutorial covers version 6.0.10, but the steps are almost the same for any Tomcat 6.0.x version. For coverage of Tomcat 5.5, see the separate Tomcat 5.5 tutorial. For coverage of very old Tomcat versions (Tomcat 5.0.x and Tomcat 4.0.x), please see the Apache Tomcat 5.0 and 4.0 tutorial.

Using Tomcat as a deployment server or integrating Tomcat as a plugin within the regular Apache server or a commercial Web server is more complicated than what is described in this tutorial. Although such integration is valuable for a deployment scenario (see http://tomcat.apache.org/tomcat-6.0-doc/), my goal here is to show how to use Tomcat as a development server on your desktop. Regardless of what deployment server you use, you'll want a standalone server on your desktop to use for development.

The examples here assume you are using Windows, but they can be easily adapted for MacOS, Linux, Solaris, and other versions of Unix. Except when I refer to specific Windows paths (e.g., C:\blah\blah), I use URL-style forward slashes for path separators (e.g., install_dir/webapps/ROOT). Adapt as necessary.

In previous Tomcat versions, if you entered a URL ending in a slash (/) and there was no welcome-file in the directory (or servlet-mapping that matched the URL), Tomcat displayed a directory listing. In Tomcat 6, the default was changed from true to false for these directory listings. Many developers find it convenient to turn directory listings back on. To make this change, edit install_dir/conf/web.xml and change the init-param value of listings for the default servlet, as below. Do not confuse this Apache Tomcat-specific web.xml file with the standard one that goes in the WEB-INF directory of each Web application.

The first thing you should do is create a directory in which to place the servlets and JSP pages that you develop. This directory can be in your home directory (e.g., C:\Documents and Settings\Your Name\My Documents\Servlets+JSP on Windows 2000) or in a convenient general location (e.g., C:\Servlets+JSP). It should not, however, be in the Tomcat deployment directory (e.g., anywhere within install_dir/webapps).

Eventually, you will organize this development directory into different Web applications. For initial testing of your environment, however, you can just put servlets either directly in the development directory (for packageless servlets) or in a subdirectory that matches the servlet package name. Some developers simply put all their code in the server's deployment directory (within install_dir/webapps). I strongly discourage this practice and instead recommend one of the approaches described in the deployment section. Although developing in the deployment directory seems simpler at the beginning since it requires no copying of files, it significantly complicates matters in the long run. Mixing locations makes it hard to separate an operational version from a version you are testing, makes it difficult to test on multiple servers, and makes organization much more complicated. Besides, your desktop is almost certainly not the final deployment server, so you'll eventually have to develop a good system for deploying anyhow.

Note that the preconfigured Tomcat version already contains all the test files, has shortcuts from the development directory to the deployment locations, and has shortcuts to start and stop the server.

This course is intended for staff who are new to Linux / Unix / Java and will be responsible for the installation, support and maintenance of Web applications using those technologies.

The first part of the course gives you an overview of Linux / Unix / OSX operating systems (they're all similar) as a user, and also the administration functions. It then goes on to cover the aspects of networks and the web you'll need to know about if you're responsible for looking after web applications in Java on these platforms.

We have a brief look at the Java language, but this isn't a programming course - we concentrate on explaining, installing and configuring Java and the various associated technologies. You'll learn how to troubleshoot Java problems even if you're not deep into the coding itself.

Web applications in Java often run in the Tomcat container, which itself is often accessed from within Apache. Both Apache and Tomcat are highly configurable pieces of software, and within them each web application that you deploy can be individually configured. Our course studies the sourcing, configuration and deployment of both Apache and Tomcat, the linking of them together, and the deployment of application within them. Administration tasks such as monitoring logs, and setting up and watching security issues are also covered.

The final part of the course introduces relational databases, and taking MySQL as an example shows how it is added to the mix of technologies to provide a complete solution. Once again, we have a brief overview of the language (SQL) and we concentrate on installation, configuration, security, use in association with other technologies, data backup, and similar topics.