Setting Up Home PCs with tomcat and using it in eclipse

1.  For your home PC, all you need in your filesystem is an image of the same tomcat filesystem tree we are using on UNIX.  This is provided in $cs636/tomcat.zip.  Of course you don't have to use your assigned port numbers at home. Just use the default port 8080, plus 8005 for shutdown. Note that we do NOT want to install tomcat as a service.  We want to use it as a user-level program, so it's easy to bring up and down.  I have my tomcat installed at c:\tomcat-6.0, for easier access from the command line.  You can copy or rename the whole thing to a different location if you decide later you don't like the first spot.

2 You don't need to set CATALINA_HOME as an environment variable for tomcat itself, but we will need it for our build.xml, so set it up. I'm assuming you already have JAVA_HOME set up as an environment variable. For example, I have CATALINA_HOME defined as C:\tomcat-6.0. Also define TOMCAT_URL as http://localhost:8080.  Add %CATALINA_HOME%\bin to your Path to allow command-line startup and shutdown.bat of tomcat.  (shutdown itself is a system program, so use shutdown.bat) Since the HTTP tool wget.exe is also in this bin, it will now be available to you. Also tcpmon.jar, another tool.

3.  Optional. If you prefer icons to commands for starting up and stopping tomcat outside eclipse, make two shortcuts as follows:  This assumes tomcat is installed at c:\tomcat-6.0. You can change it as necessary.
Shortcut "start tomcat":
Target:  c:\tomcat-6.0\bin\startup.bat
Start in: c:\tomcat-6.0
For a nice icon, browse to your top-level tomcat directory and find tomcat.ico
Shortcut: "stop tomcat":  same Shortcut Properties as "start tomcat" except replace start with stop in the Target:
Target:  c:\tomcat-6.0\bin\shutdown.bat

4. In a new DOS box, check your environment variables with "set" and "path" in a new command window..

5. Quick test of tomcat: watch the startup output.  You may see a pop up from the Windows firewall, but this should not prevent tomcat from working when accessed from the same machine (this is all we need), so don't be stopped by it. Start up a browser and try URL http://localhost:8080  Hopefully you'll see the familiar tomcat home page.  If nothing is there, you can see what ports are in use, including listening ports, by "netstat -a".  If you installed JEE in a privileged account (System Admin privileges) you may have Sun's app server running on 8080 as a service.  Shut it off as a service.

Eclipse and tomcat: Simplified and enhanced from eclipse (Indigo version) docs
    Help>Contents>Web Tools Platform User Guide>Developing Web service applications>
                Web Services overview> Workspace and tools> Configuring your workspace>
                 Creating an Apache Tomcat server and Web Project (see if you can find it!)

Once you have installed the tomcat server outside eclipse, create a Tomcat server in the eclipse workbench by doing the following:

  1. From the File menu, select New > Other > Server > Server > Next.
  2. Select Tomcat v6.0 as the server type, and click Next.
  3. On the Tomcat server page:
    1. Enter a server name, say Tomcat v6.0
    2. Specify where Tomcat is installed. (maybe c:\tomcat-6.0)
    3. "Workbench default JRE" should be OK.  If worried, click Installed JREs, and check that your JDK 6 is showing as default.
  4. Click Finish. Or next through 2 more windows to see settings. Allow eclipse to show the "JEE perspective", the eclipse UI mode for JEE.  Note that you can change perspectives in eclipse via buttons that show up on a tab: Java, Debug, Java EE, etc.
  5. To see the server object you have created in the workspace, from the Window menu select Show view > Other > Server > Servers > Ok.  The Servers window should now show.  (Maybe it was showing before this: look for a tab with "Servers".) You can also find it as the "Servers" project in the Package Explorer, but this representation doesn't seem to have a way to make the Servers window show. The Servers window should show when you select the Java EE perspective.
  6. NOT IN USER GUIDE BUT IMPORTANT: In the Servers window, double click the line describing tomcat 6.0 (or 7.0) in the Servers window, to see the Overview window giving configuration info on eclipse's handling of tomcat.  Select "Use Tomcat installation", and (for 7.0) make sure that "Deploy Path" is webapps, not wtpwebapps.   If this is not selected, eclipse will run the tomcat site in a more or less secret location, greatly confusing simple use. If you can't see the tomcat at http://localhost:8080, recheck this setting.

To build a dynamic Web project (what we need for pa2 and any other project using servlets) that points to the Tomcat server that you have created:

  1. Create the dynamic Web project by selecting File > New > Project... > Web > Dynamic Web project. Enter the following information:
    • Project Name: enter a project name
    • Uncheck default location if you want to use provided files.
    • Target runtime: Tomcat server v6.0. .
    • Ensure that Add project to an EAR is not selected.
    • For provided-files projects, uncheck "Generate web.xml deployment descriptor" on the Web Module pane of the Dynamic Web Project wizard, to avoid overwriting a provided web.xml.
  1. Click Finish.
  2. To associate the project with the server, right-click the Tomcat server you created in the Server view and select Add and remove projects. Select the project from the Available projects list and click Add.

To start tomcat from eclipse, first be sure to stop it outside eclipse if needed, then right-click the server in the Servers window and choose Start. Or use the green start icon at the top of the Servers window.  You can start it in debug mode similarly, and set breakpoints in your servlet code.