Setting Up Home Systems with tomcat and using it in eclipse

1.  For your home system, all you need in your filesystem is an image of the same tomcat filesystem tree we are using at cs.umb.  This is provided in $cs636/  Of course you don't have to use your assigned port numbers at home. Just use the default port 8080 (as provided in the zip), 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-8.5, 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, as described in DevelopmentSetup.html for Windows, Linux, and MacOSX. Use the same procedure for CATALINA_HOME. For example, I have CATALINA_HOME defined as C:\tomcat-8.5 for my Windows PC. 

For Windows, 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.

For Linux and MacOSX, add $CATALINA_HOME/bin to your PATH environment variable.   PATH=$PATH:$CATALINA_HOME/bin; export PATH

Similarly add TOMCAT_URL as an environment variable, with value http://localhost:8080. This variable is used in the web projects' build.xmls.

3.  Optional, for Windows. 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-8.5. You can change it as necessary.
Shortcut "start tomcat":
Target:  c:\tomcat-8.5\bin\startup.bat
Start in: c:\tomcat-8.5
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-8.5\bin\shutdown.bat

4. In a new shell/CMD window, check your environment variables with set (Windows) or env (Linux/MacOSX)

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 (Mars 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, if you want to use eclipse debugging of servlet code, and/or want eclipse to automatically reflect your source edits in the deployed code.  If you don't want this capability, skip this whole procedure (1. to 8. below) and just run tomcat outside eclipse, and use eclipse just for editing code and running in client-server mode.

  1. From the File menu, select New > Other > Server > Server  and click Next.
  2. Select Apache>Tomcat v8.5 as the server type (available in eclipse Oxygen, though not earlier versions), and click Next.
  3. On the Tomcat server page:
    1. Specify where Tomcat is installed. (maybe c:\tomcat-8.5)
    2. "Workbench default JRE" should be OK.  If worried, click Installed JREs, and check that your JDK 6 is showing as default.
  4. Click Finish. Allow eclipse to show the "Java EE perspective" if it hasn’t already, the eclipse UI mode for Java EE.  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: Make sure the Servers view is showing, using Window>Show View>... In the Servers view, with tomcat running but no projects added, double click the line describing tomcat 8.5 in the Servers window, to see the Overview window giving configuration info on eclipse's handling of tomcat.  Select "Use Tomcat installation (takes control of Tomcat installation)".   If this is not selected, eclipse will run the tomcat site in a more or less secret location, greatly confusing simple use. Also set the deploy path to webapps, not wtwebapps. If you can't see the tomcat at http://localhost:8080, recheck this setting.  Here is an image of a setup: pic
  7. 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.
  8. Test your setup: Stop any tomcat you started outside of eclipse. Start the server in the Servers view. Browse to http://localhost:8080 to see the tomcat and http://localhost:8080/servlet1/servlet/HelloWorld to see servlet1’s page.  Try out eclipse’s browser by finding the world icon near the top of its window. This browser is not as useful as Chrome, however.

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

With eclipse oxygen, just use Open Projects from File System using a setup like music3-setup that has a WebContent directory.

The old long way, in case you are trying to use an older eclipse:

  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 v8.5 .
  • Ensure that Add project to an EAR is not selected.
  • For provided-files projects, uncheck (if necessary) "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.