Friday, 16 November 2012

Apache Tomcat Installation and Configuration

Apache Tomcat :


                     Tomcat is not the same as the Apache web server, which is a C implementation of a HTTP web server; these two web servers are not bundled together, although they are frequently used together as part of a server application stack. Apache Tomcat includes tools for configuration and management, but can also be configured by editing XML configuration files.

Latest version available is 7.x which has an added support for Servlets 3.0 and JSP 2.2 Specifications.

Here, in this post, I am providing the detailed description on "Installing and Configuring" Tomcat Server in Windows.

Download :
You can download the latest version from the Apache Tomcat Website
Downloads are available in different file formats for different Operating Systems.

For Windows Operating Systems, download either
1. Windows Installer
2. Windows Zip File

Windows Installer is an easy-to-run tool of Tomcat server, which combines the installation and configuration making the task of user or developer more easier. But, it is not a recommended version, since, one cannot know the process of configuring and installing the server according to his needs.

Following are the series of steps of installing and configuring the Tomcat Server :


    a) In Windows , You can install it either through Executable file
        (or) through a set of binary files.
   
    b)   Download the 32-bit Windows Binary Distribution file from the website.

        Prefer to use the Binary Distribution file.

INSTALLATION AND CONFIGURATION :
Steps :
1. If it is a Executable File,simply double-click it and then go through the series of steps in the installation wizard dialog box shown. 

2. In case of Binary Distribution, extract the Zip file to a directory , copy the entire directory in to another  location where you would prefer to work.

Generally , the name of the root directory will be "apache-tomcat-version-no." 
Rename it to your choice , for eg. tomcat7.

3.  In order to run the Tomcat server , you need to specify the path for the Java Development tools such as javac , java which are present in the java installation directory, if you have installed java. The JDK must be installed in your system. Verify whether your system is installed with either JDK or only JRE. JRE alone is not sufficient for running the Tomcat Server.
                
After verifying and confirming, java is installed in your system, you can proceed with the following steps.

4. Creating the Environment Variables
  • JAVA_HOME (required)
  • CATALINA_HOME (optional)
  • CLASSPATH  (required)
       An Environment Variable is a "Name and Value" Pair which is defined either by a program or by the user in the operating system, for other programs to make use of it.



CATALINA_HOME :  
  • It points to Tomcat installation directory. 
  • It is optional, because it is not needed for running the server. It is used to just define the path of Tomcat installation directory to the operating system and other programs.
JAVA_HOME : 
  • It points to Java installation directory.
  • It is required, because Tomcat server requires java to compile and execute the Servlet and JSP Pages and it does not come bundled with java within it.
CLASSPATH : 
  • It points to Java Class Libraries. 
  • Here, we should add Servlet jar files present in the Tomcat\lib  directory.
  • It is the Variable, that java tools use to locate classes and class libraries
  • It is required, because Servlet and JSP libraries are needed to compile the Servlets and JSPs and these libraries are not available with the JDK. Hence, we should add these libraries to the CLASSPATH, in order to compile those files.
 If java is installed in C:\java directory. Then the directory structure of java directory will look like this :

C:\
    |
    |--java
          |
          |--bin
                 |--javac.exe
                 |--java.exe
                 |--javah.exe
          |
          |--lib
          |--docs
          |--db
          |--demo
          |

Then, the "JAVA_HOME", should contain the value as "C:\java\".

If tomcat is installed in C:\tomcat directory. Then the directory structure of Tomcat directory will look like this :

C:\
    |
    |
    |--tomcat
          |
          |--bin
                 |-- startup.bat
                 |-- shutdown.bat
                 |-- catalina.bat
          |
          |--conf
                  |-- server.xml
                  |-- web.xml
                  |-- tomcat-users.xml
                  |-- context.xml
          |--lib
                 |
                 |-- jsp-api.jar
                 |-- servlet-api.jar
          |--logs
          |--temp
          |--webapps
          |--work
          |

Then, the "CATALINA_HOME", should contain the value as "C:\tomcat\"
 And the "CLASSPATH", should contain the value as "C:\tomcat\lib\servlet-api.jar"

Note : Do not include the quotations.

For Eg :
                ---------------------------------------------
                        Variable    :    JAVA_HOME
                        Value        :    C:\Program Files\java\
                ---------------------------------------------

                ---------------------------------------------
                        Variable    :    CATALINA_HOME
                        Value        :    C:\tomcat\
                ---------------------------------------------

                ------------------------------------------------
                        Variable    :    CLASSPATH
                        Value        :    C:\tomcat\lib\servlet-api.jar;
                -------------------------------------------------
The process of creating the Environment Variables in Windows is shown below :

In Windows XP
  1. Right Click on "My Computer" icon.
  2. Select Properties .
  3. Click on "Advanced" tab
  4. Click on Environment Variables button
  5. A Dialog box will be opened with the Title "Environment Variables".
  6. This dialog box contains two panels. a.) User Variables b) System Variables
  7. Click "New" Button from any one of the panels.
  8. It will display a dialog with Name and Value fields.
  9. Enter JAVA_HOME in the Name field and actual path in the Value field.
  10. Enter CATALINA_HOME in the Name field and actual path in the Value field.
  11. Enter CLASSPATH in the Name field and actual path's in the Value field.
  12. Click Ok.
  13. Click OK
 In Windows 7
  1. Right Click on "My Computer" icon.
  2. Select Properties .
  3. Click Advanced System Settings link on the left panel.
  4. Click on "Advanced" tab
  5. Click on Environment Variables button
  6. A Dialog box will be opened with the Title "Environment Variables".
  7. This dialog box contains two panels. a.) User Variables b) System Variables
  8. Click "New" Button from any one of the panels.
  9. It will display a dialog with Name and Value fields.
  10. Enter JAVA_HOME in the Name field and actual path in the Value field.
  11. Enter CATALINA_HOME in the Name field and actual path in the Value field.
  12. Enter CLASSPATH in the Name field and actual path's in the Value field.
  13. Click Ok.
  14. Click OK

 5. Now the installation of the Tomcat Server was completed.

 6. It is the time to test , whether the server is running successfully or not.
               
      You can check whether your server is running or not :
               
       1. Open a command prompt and move to %CATALINA_HOME%\bin
       2. type startup.bat 
       3. This batch file starts up the server
       4.Now open a browser and in the address bar , type the following :
                   
            http://localhost:8080/
               
           If you see a page with the Tomcat Instructions , then the installation is successfull.
                   
       Otherwise , recheck the previous steps .

  • In some systems, other programs may  be using the port 8080 . In that case, tomcat server won't start.
  •  If you want to change the port number, locate 'server.xml' in the "conf" directory where Tomcat is installed.
  •  Open Server.xml, and find the following line in the file.                                                                                      <Connector port="8080" protocol="HTTP/1.1"
  • Change the port to a number, on which you wish your server to listen to.
  • The port numbers values range from 0 to 65535.
  • 0 to 1024 are reserved for system purposes. You cannot use them.
  • You can use any of the remaining ports.
  • After changing the ports, shutdown and start the server as described above.
I hope this tutorial is useful. Thank you for reading my blog.

No comments:

Post a Comment