Monday, February 14, 2011

Apache Tomcat - What is it...

What is Apache Tomcat?
-          Open source servlet container.
-          It implements Java Servlet & JSP specification.
-          Provides pure Java HTTP Web Server environment.
It should not be confused with Apache Web Server which is totally different – basically a C implementation of HTTP web server.

What are the main components of Tomcat?
-          Catalina – Servlet Container.
-          Coyote – HTTP Connector. It listens for incoming connections on specific TCP ports on server and forwards them to tomcat engine and then from server to clients.
-          Jasper – It is nothing but a JSP engine. It parses JSP files & compile them into Java code as servlets. It also detects changes to JSP files at runtime and recompiles if necessary.

Directory Structure
·         /bin – Various binaries and script files. Main scripts to see are the startup & shutdown scripts.
·         /conf – Various configuration files. The most important configuration file is server.xml.
·         /logs – Default location for log files.
·         /webapps – All your webapps will be placed in this folder.

To learn how you can install and configure tomcat see the article – Installing Apache Tomcat.

Basic Apache Tomcat Installation - Step by Step

Prerequisite: Tomcat engine is a Java program so before you start installing tomcat you should have Java installed. That’s the only pre-requisite for Apache Tomcat.
Step1:  Download Tomcat.
There are two types of downloads available:
-          Binary distribution – Where you can simply download the binaries and use them.
-          Source Code – Complete source which developers can compile. Useful for any customization/tunings a developer might need to do.
During download you also want to make a choice if you want to install tomcat as a service or not.
If on a windows system you want to run tomcat as a service then from the core distribution you can select 32/64 bit Windows Service Installer. It is a GUI installer that will install tomcat on your machine. The normal 32bit Windows or other code distribution packages contains tomcat binaries in its directory structure. Users can simply keep this and start and stop tomcat from /bin/startup or /bin/shutdown batch or sh files depending on which platform they are running it.
Step2:  Configuring.
To start using tomcat there isn’t any configuration as such. You can simply start using tomcat as is from this stage. The only item you need to keep in mind is that you have Java installed and proper environment variable is set.
Set JAVA_HOME environment variable to the folder that contains JDK.

Step3: Starting Tomcat.
If you have download tomcat as a zip all you need to do is unzip it, navigate to bin folder and run startup.bat to start tomcat. Once started successfully it shall give you a message in command window saying server startup in xyz seconds.
You can also open IE and navigate to http://localhost:8080/ if you see a page displayed about tomcat that means you have successful installed and configured tomcat.
By default tomcat runs on 8080 port.
Step4: Stop Tomcat
From /bin folder use shutdown.bat script. Or simply close the command windows that came up when you started tomcat.

Step5: Looking for errors
If there were some errors during tomcat startup you can find them in Catalina files of /log folder.