Go Back   Wiki NewForum | Latest Entertainment News > Career Forum & Tips > Tech Forum & Tutorial > Java Forum & Tutorial


Configuring & Using Apache Tomcat


Reply
Views: 3350  
Thread Tools Rating: Thread Rating: 4 votes, 2.25 average.
  #1  
Old 06-02-2009, 02:05 PM
bholus7
Guest
 
Posts: n/a
Default Configuring & Using Apache Tomcat

Configuring & Using Apache Tomcat

Following is a guide to installing and configuring Apache Tomcat 5.5 for use as a standalone Web server (for development) that supports servlets 2.4 and JSP 2.0. (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 5.5.17, but the steps are almost the same for any Tomcat 5.5.x version. For coverage of Tomcat 6, see the separate Tomcat 6 tutorial. For coverage of older Tomcat versions (Apache Tomcat 5.0.x and Apache Tomcat 4.0.x), please see the Apache Tomcat 5.0 and 4.0 tutorial.


Executive Summary




Most people will just want to download the preconfigured Tomcat version, set JAVA_HOME and CLASSPATH, and they are done. But following is a summary of the steps for people who want to change the configuration or do it themselves. This section gives a summary of the required steps; I give extremely detailed instructions in the following sections.

* Install the JDK. Make sure JDK 1.5 or 1.4 is installed and your PATH is set so that both "java -version" and "javac -help" give a result.
* Configure Tomcat.

1. Download the software. Go to http://tomcat.apache.org/download-55.cgi and download and unpack the zip file for the current release build of Tomcat 5.5. Using Tomcat with JDK 1.5 (Java 5) is preferred, but if you use JDK 1.4, you have to also download and unpack the "Compat" zip file.

The the preconfigured Tomcat version already contains the "Compat" files and can be used with either Java 5 (1.5) or Java 1.4.

2. Set the JAVA_HOME variable. Set it to refer to the base JDK directory, not the bin subdirectory.

3. Change the port to 80. Edit install_dir/conf/server.xml and change the port attribute of the Connector element from 8080 to 80.

4. Turn on servlet reloading. Edit install_dir/conf/context.xml and change to .

5. Enable the invoker servlet. Go to install_dir/conf/web.xml and uncomment the servlet and servlet-mapping elements that map the invoker servlet to /servlet/*.

6. Change the DOS memory settings. If you are on Windows 98/Me and get an "Out of Environment Space" error message when you start the server, right-click on install_dir/bin/startup.bat, select Properties, select Memory, and change the Initial Environment entry from Auto to at least 2816. Repeat the process for install_dir/bin/shutdown.bat. Only needed for Windows 98 and ME; not necessary on recent versions of Windows.

7. Set the CATALINA_HOME variable. Optionally, set CATALINA_HOME to refer to the top-level Tomcat installation directory. Not necessary unless you copy the startup scripts instead of making shortcuts to them.

8. Use a preconfigured Tomcat version. Optionally, use a version of Jakarta Tomcat that has all of the above changes already made, and has the test HTML, JSP, and servlet files already bundled. Just unzip the file, set your JAVA_HOME and CLASSPATH variables, and you are ready to go.

Reply With Quote
  #2  
Old 06-02-2009, 02:06 PM
bholus7
Guest
 
Posts: n/a
* Test the server.
1. Verify that you can start the server. Double-click install_dir/bin/startup.bat and try accessing http://localhost/.

2. Check that you can access your own HTML & JSP pages. Drop some simple HTML and JSP pages into install_dir/webapps/ROOT and access them with http://localhost/filename.

3. Try Compiling and Deploying Servlets.
* Set up your development environment.

1. Create a development directory. Put it anywhere except within the Tomcat installation hierarchy.

2. Make shortcuts to the Tomcat startup & shutdown Scripts. Put shortcuts to install_dir/bin/startup.bat and install_dir/bin/shutdown.bat in your development directory and/or on your desktop.

3. Set your CLASSPATH. Include the current directory ("."), the servlet/JSP JAR files (install_dir/common/lib/servlet-api.jar and install_dir/common/lib/jsp-api.jar), and your main development directory from Step 1.

4. Bookmark the servlet & JSP javadocs. Add install_dir/webapps/tomcat-docs/servletapi/index.html and install_dir/webapps/tomcat-docs/jspapi/index.html to your bookmarks/favorites list.

* Compile and test some simple servlets.

1. Test a packageless servlet. Compile a simple servlet, put the .class file in install_dir/webapps/ROOT/WEB-INF/classes, and access it with http://localhost/servlet/ServletName.

2. Test a servlet that uses packages. Compile the servlet, put the .class file in install_dir/webapps/ROOT/WEB-INF/classes/packageName, and access it with http://localhost/servlet/packageName.ServletName.

3. Test a servlet that uses packages and utility classes. Compile a servlet, put both the servlet .class file and the utility file .class file in install_dir/webapps/ROOT/WEB-INF/classes/packageName, and access the servlet with http://localhost/servlet/packageName.ServletName.

This third step verifies that the CLASSPATH includes the top level of your development directory.
* Establish a simplified deployment method.

1. Copy to a shortcut. Make a shortcut to install_dir/webapps/ROOT. Copy packageless .class files directly there. With packages, copy the entire directory there.

2. Use the -d option of javac. Use -d to tell Java where the deployment directory is.

3. Let your IDE take care of deployment. Tell your IDE where the deployment directory is and let it copy the necessary files.

4. Use ant or a similar tool. Use the Apache make-like tool to automate copying of files.

* Get more info. Access the complete set of Tomcat docs, get free JSP and servlet tutorials, read the official servlet and JSP specifications, get JSP-savvy editors and IDEs, look for J2EE jobs, etc.
Reply With Quote
Reply

New topics in Java Forum & Tutorial





Powered by vBulletin® Version 3.8.10
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
WikiNewForum)