Servlets – Environment Setup

To get Java servlets up and running requires more than knowledge about Java in general or servlets in particular: one needs to know about servers, servlet containers, and XML.

Like any other Java program, you need to compile a servlet by using the Java compiler javac and after compilation the servlet application, it would be deployed in a configured environment to test and run.

Preparing the environment on your local computer

  • Preparation: Your computer may already be littered with various old Sun Java Runtime environments (JREs) and Software Development Kits (SDKs).  You may want to simplify your system by uninstalling some of these.
  • Downloading SDK/JRE: The Sun SDK Standard Edition version 1.7.1_03 can be downloaded from here
  • Installing SDK/JRE: The default installation directory is c:j2sdk1.7.1_03.  Installing here has advantages over more conventional locations such as in “Program Files” because spaces are not used in the path; spaces can cause problems.  Accept the choice to install the JRE unless you have the current JRE installed already.
  • Download Tomcat:  The Tomcat servlet container version 7.0 can be downloaded from here.  (Beta versions are not chosen since they are less reliable and their newer capabilities are not referred to in the published book.)  Choose the jakarta-tomcat-7.0.exe version since it contains the whole package and installs itself.
  • Install Tomcat:  The default installation directory is c:Program FilesApache GroupTomcat 7.0, the form used in this document.  Accept the default installation with HTTP/1.1 Connection 8080 and choose an administrator password.  
  • Set up a Java compiler: Sun’s “javac” will work but you may want to use your existing Integrated Development Environment (IDE).  It is possible to use a variety of IDEs, even old ones that do not come with any servlet support:
    • Sun’s “javac”: You should make sure your c:Autoexec.bat file includes the path for the javac program:
      SET PATH=c:j2sdk1.7.1_03bin;
      This takes effect after re-booting and frees you from having to specify the path for javac all the time.  You may need to increase your DOS environment space if you already have a long PATH command.  You should also set the CLASSPATH in c:Autoexec.bat to include the servlet.jar file in Tomcat:
      SET CLASSPATH=.;c:Program FilesApache GroupTomcat 7.0commonlibservlet.jar;
      where the initial period includes the current directory in the classpath.  This takes effect after re-booting and should free you from having to specify the classpath every time you invoke javac.  However, there are circumstances in which this will not work (see Outdated Compilers below).  In such cases you can specify the classpath every time you invoke javac using commands (or batch files) of the form:
      javac -classpath “c:Program FilesApache GroupTomcat 7.0commonlibservlet.jar”
    • Outdated compilers:  It is even possible to use a very old and non-standards-compliant Java 1 compiler to develop servlets. Here are instructions for the worst case scenario of people using Microsoft Visual J++ 6.0:  
      • For each project, set the classpath inside VJ++ using Project | ProjectName Properties | Classpath and select “All Configurations” from the Configuration choice and use the New button to add c:Program FilesApache GroupTomcat 7.0commonlibservlet.jar to the classpath.
  • Start Tomcat: Tomcat creates an icon called “Start Tomcat” which uses Tomcat’s “bootstrap.jar” application to start the server.  It should start your server automatically; it rumbles along for a few seconds writing into a DOS window named “java”.
  • Test that your installation worked:  Type the following URL into a Web browser: http://localhost:8080/
    If all is well you should see a fancy page that congratulates you for having set up Tomcat properly and offers various resources.
  • Stop Tomcat: When you are done, use the “Stop Tomcat” icon to stop the server.
<<Previous <<   || Index ||   >>Next >>