Tomcat

Download: www.coreservlets.com/Apache-Tomcat-Tutorial/Preconfigured-Tomcat-5.5-Version.html

The easiest way to install Tomcat is to use the preconfigured version available at the link above.

After downloading, right click on the zip file and choose Extract All. Browse to “C:\Program Files”; the extraction process will create the “apache-tomcat-5.5.17” folder. If you extract the files to the default folder (which will be the folder where the zip file is located) just move the files to C:\Program Files\apache-tomcat-5.5.17 (some versions will be “Jakarta-Tomcat”).

By default, your browser will be watching port 80 rather than 8080 which means you would have to type http://localhost:8080/ rather than http://localhost/ to check your work. The pre-configured version linked above includes the following change. You can change the port number from 8080 to 80 easily. Navigate to C:\Program Files\apache-tomcat-5.5.17\conf\ and open server.xml in a text editor (NotePad or WordPad). Do a search for “8080”. There will be some comments that will catch the search first but following the comments you will find the actual instruction pointing to 8080. Changing it to “80” will match it to your browser's default.

Create or change the system's Classpath variable to include the Tomcat jsp and servlet api's under the Control Panel --> System --> Advanced --> Environmental Variables. If a Classpath variable doesn't already exist, click on New and enter "CLASSPATH" in the variable name line. The Variable Value box should include the following:

.;C:\Program Files\apache-tomcat-5.5.17\common\lib\servlet-api.jar;C:\Program Files\apache-tomcat-5.5.17\common\lib\jsp-api.jar;

The line in the Classpath above should begin with a period followed by a semi-colon. This allows subdirectories to be used in the Classpath.

While you have the Environment Variable screen open, add C:\Program Files\apache-tomcat-5.5.17\bin to the Path variable. Add another environment variable called “CATALINA_HOME” and point it to the Tomcat directory -- the default is C:\Program Files\apache-tomcat-5.5.17.

Restart the workstation for environment variable changes to take effect.

Test your setup as follows: Click on C:\Program Files\apache-tomcat-5.5.17\bin\startup.bat and see if a DOS window opens up and the server starts. You can right click on the startup.bat file and drag it to the desktop to create a shortcut (be careful not to move the actual file -- just create a desktop shortcut). Do the same with the shutdown.bat file also in the bin directory. This will make starting and stopping the Tomcat server much easier until you get the plugin working inside Eclipse. You should see a screen similar to this after a successful startup (some of the version numbers may have changed since this screen capture was created).

Tomcat startup screen

If you have problems, one way to discover their nature is to start Tomcat from a Command box by entering "startup.bat" (or C:\Program Files\apache-tomcat-5.5.17\bin\startup.bat if you didn't set the Path environmental variable above). The rather friendly error messages may provide an insight into the specific problem causing Tomcat to fail to start.

Open a browser and type in a URL of http://localhost/. If everything's working you should see the Apache-Jakarta Tomcat welcome page.

If the correct page doesn't open in the browser go back through and check all of the environment variables in the Control Panel for typos and omissions. Although you are operating in a Windows environment, the Java and Tomcat directories need only be present and pointed to correctly in the environment variables in either location. There aren't any other “hidden” connectors as you might expect in standard Windows components.

Tomcat Homepage

Congratulations if you see the Tomcat sample page! You're halfway to a great development environment! Take some time to check the sample JSP and Servlet pages provided by Tomcat in the C:\Program Files\apache-tomcat-5.5.17\webapps\ directory. You can see the source code and the resulting web page for each example. For example, enter http://localhost/jsp-examples/num/numguess.jsp in the address bar of a browser and play their simple number game.


PATH versus CLASSPATH

If you're not confused by the distinction between the environmental variables “PATH” and “CLASSPATH” you probably don't need to be reading this tutorial.

PATH is where the operating system (XP or Vista in our case) goes to find executables (EXE's). Thus you (or sometimes the program installer) will put the “bin” directories of Java, Tomcat, and MySQL in the PATH. You should confirm the only path to a Java bin is the one pointing to the JDK you are using. The system will accept the first one and ignore any conflicting bin's that follow but you want to keep your environment variables as clean as possible. You can check the Path variable by bringing up a Command Prompt (Start Programs --> Accessories --> Command Prompt) and type in "Path". This should bring up the path variable in the command box.

CLASSPATH is where Java (the JVM) will look for jar files (i.e., compiled classes) when it's running programs. So your CLASSPATH environmental variable will have paths to two jar files for Tomcat and one for MySQL -- and probably others if you have other Java programs on your computer.


Tomcat and Vista Security

Vista with User Account Control (UAC) running causes a problem. Vista normally runs everybody -- including administrators -- in a non-administrative role. This provides additional security and makes it more difficult for intruders to run programs requiring administrative privileges. You can right click on the Tomcat desktop shortcut if you made one and chose “Run As Administrator”. Do this for both Tomcat Startup and Shutdown shortcuts. You will also need to run Eclipse in administrator mode.

For a more permanent solution, right-click on the shortcut and chose “Properties --> General --> Advanced” and check the box to run the program as administrator. Do this for both the Tomcat Startup and Shutdown shortcuts.

Tomcat overwrites an xml file when it starts up. This will fail if run on a Vista computer without administrator privileges. The command line box will show some errors but it will also finish with the Server startup message so you may get the impression you have a good Tomcat startup.

This is not a problem on XP computers.