Tomcat
The Java web applications that we develop have to be deployed in a servlet container. In this class, we are using Tomcat 6. We use Eclipse as IDE for the development, which integrates nicely with Tomcat. This page will describe how to configure Eclipse to use your Tomcat installation.
First a quick note on how you can run Tomcat though. Once you downloaded and installed Tomcat on your system, you can start Tomcat. How is start Tomcat depends on your system. If you have a Windows computer, you should have a program called Tomcat6w.exe, which provides you a graphical interface to interact with Tomcat. If you have a Mac, you can simply start Tomcat by typing
/Applications/apache-tomcat-6.0.44/bin/startup.sh
This of course assumes you installed Tomcat in your Applications folder.
On a Linux server, you can do it similarly to the way you start Tomcat on a Mac or if you have a service installed to start Tomcat type
service tomcat6 start
Tomcat will attempt to start all applications that are in Tomcat's 'webapp' folder. You usually deploy an application to Tomcat by putting its war-file into that folder. The Tomcat version from Apache's Tomcat page usually ships with a manager application, that also allows you to deploy applications to Tomcat via the browser.
Tomcat & Eclipse
So far so good. But what happens when you add your Tomcat to Eclipse? The main important thing for you to remember is that Eclipse does not use the Tomcat instance you've installed on your system. It'll create a new Tomcat instance using your installed 'Tomcat Runtime'. This means that if you have web applications in your Tomcat's webapp folder those won't be available when you run Tomcat in Eclipse. Similarly, if you made changes to your Tomcat configuration, those will most likely not be taken up in Eclipse. Usually, you also do not have the manager GUI when running Tomcat from Eclipse.
Configuring Eclipse
As usual, there are several ways to achieve what we want to do. Here, we will go through the "Servers" view as it is a useful view when working with web applications. Go to "Window -> Show View -> Others..."
Then select from the folder "Server" the view "Servers". If you do not have such a folder, double-check that you have Eclipse's Web Tools Platform (WTP) installed.
In the view that opens, right click and select "New -> Server". A wizard should open that is called "Define a new Server".
Select the type of server you'd like to create (in our case Tomcat 6). If you choose a type that you used before, you should a property called "Server runtime environment" that shows the runtimes you've already defined. If that is the case, simply make sure it is the correct runtime and click "Finish" and you're done.
If you haven't defined a runtime yet, click "Next". The next screen will ask you to tell Eclipse where you Tomcat runtime is installed. Use the browse button to find your Tomcat's installation directory.
Click "Finish". The "Servers" view should now show you the Tomcat instance you just added.
Note: In the above example, a Tomcat 7 instance was added as a Tomcat 6 instance already existed for the workspace.
Running Tomcat
You can use the "Servers" view to start, stop, and restart your Tomcat instances. Just right click on a server and use the context menu or select the server and use the buttons in the view. If you made changes to your application, you can simply restart your Tomcat through the view, and the changes will automatically be deployed with the restart. You do not have to go through "Run on Server" in the context menu of your project after you restarted Tomcat. Just a restart is usually enough.