Integrating Eclipse and Tomcat - WTP (Web Tools Platform) Guide
Using the Eclipse IDE in conjunction with Apache Tomcat allows you to unify your development environment with your server. No more switching back and forth between your IDE and other tools as you deploy applications and configure your server. Using Tomcat within Eclipse means all configuration, coding, deployment, and management can happen within the familiar Eclipse interface.
The Eclipse project offers application server integration via a set of plugins called the Web Tools Platform. This set of components includes engines for managing, developing, compiling, and deploying web artifacts, as well as plugin support for all non-legacy versions of Apache Tomcat and a number of other application servers. In this guide, we'll walk you step by step through installing WTP and the Eclipse Tomcat plug-in, setting up Tomcat servers in Eclipse, and developing and deploying your first servlet. (Before ping in, please note that this tutorial assumes you have already successfully installed Tomcat on your machine, either by downloading and configuring a binary distribution from the Apache website or using the Apache Tomcat installer for Windows.
If you installed Tomcat using a repackaged platform-specific distribution, such as those available from the RPM or JProject repositories, you may have some trouble getting Tomcat to start using these instructions. Fortunately, the latest versions of WTP include very specific error messages to help you fix any potential problems, which are usually caused by re-named or missing JAR files.)
Tip: Using the Eclipse WTP in development? Try Tcat Server - enterprise Tomcat made simple, with key features such as application provisioning and group deployment that save you time during development and eliminate tedious administrative tasks in production. Click here to download!
You can obtain the Eclipse Web Tools Platform as a binary distribution from the Eclipse project site, but most users will find it much easier and suited to their needs to install the WTP using Eclipse's internal package manager.
The package manager can be found in Eclipse's Help Menu under the "Install New Software..." menu item. From the drop down "Work with:" list of repositories, choose either the WTP Repository itself, or one of the core Eclipse repositories (Galileo, for example). The majority of WTP deliverables are included in the core repositories.
Once you've selected the WTP distribution appropriate for your SDK, Eclipse will automatically determine the components you need and install them, including the Tomcat plugin. If you would like more detailed installation instructions, please visit Tomcat Eclipse, our illustrated, step-by-step guide to installing WTP for use with a Tomcat server.
Configuring The Tomcat Runtime
Now that you've installed the Web Tools Platform, you can specify Tomcat as a Runtime Environment. Setting up a Runtime Environment in Eclipse basically means telling its engines where to look for your application server, so it can utilize its components and automatically configure your workspace.
To configure Tomcat as a new Runtime Environment, select the "Preferences" menu item from Eclipse's "Windows" menu (if you are using a Mac, you can find "Preferences" under the main Eclipse menu). You will be presented with large tree of preferences. Expand the "Server" preferences, and select "Runtime Environments". If this is the first time you have configured an application server in Eclipse, the list will be blank.
On the right hand side of the dialogue box, click the "add" button to call up the "New Server Runtime Environment" dialogue. You will be presented with a tree of application server vendors. Expand the Apache folder, and choose the version of Tomcat you have installed on your system. You will be asked to provide the path to Tomcat's base directory, as well as the path to the JRE you wish to use. As you will be compiling servlets, the JRE path should actually point to your JDK.
To create a new Tomcat server in Eclipse, navigate to the "Server" tab, which is located in the lower half of Eclipse's development screen by default, and secondary click. Choose "New -> Server" from the context menu.
You will be presented with a dialogue in which you can configure high-level server setting such as default ports, server name, and host name. You can also use this dialogue to set your web application deploy path. If you would like more in depth information about setting up Tomcat servers in Eclipse, please visit Tomcat Eclipse, our illustrated step-by-step guide to using Tomcat with Eclipse.
Controlling your Existing Tomcat Installation with Eclipse
If you wish to integrate your existing Tomcat installation into Eclipse, rather than creating a new instance, follow the same steps as above for configuring a new server, and select "Use Tomcat installation" from the "Server Locations" tab of the Server Configuration menu.
Enabling Modern Context.XML Fragments
All actively supported versions of Tomcat allow web application Context Descriptors to be configured via context.xml fragments located in the application's "META-INF" directory. This allows users to make changes to applications and redeploy them without restarting the entire application server, as they would if the entries were included in "$CATALINA_HOME/conf/server.xml".
Eclipse supports this technique natively, but the option is enabled by default, in the interest of greater compatibility. If you wish to store application context information in a location other than "server.xml", check the "Publish module contexts to separate XML files" option in the "Server Options" tab of the Server Configuration menu.
Enabling JULI Logging
Apache Tomcat includes a version of the Java utility logger called JULI, which is modified for a container-based environment. Eclipse does not enable JULI by default when it creates new Tomcat servers.
In order to use JULI on your new Eclipse-configured server, copy "conf/logging.properties" from your root Tomcat installation folder into the "conf" folder of your new server. Next, in the Server Configuration menu, click the "Open launch configuration" link located in the "General Information" tab. In the "VM Arguments" field of the resulting Properties dialogue, add the JULI logging switches, as follows:
Eclipse lumps all web artifact projects, from JSPs to Servlets, into the "Dynamic Web Project" category. To begin creating a new web application, select the "Dynamic Web Project" option from the "File -> New" menu. After associating the project with a server, you can begin creating classes and JSP files, editing deployment descriptors, and so on.
If you still feel shaky and would like to build a sample servlet with directions to get your feet on the ground, check out this well-written tutorial provided on the Eclipse website, in which you will create a simple browser information servlet.
Deploying and Running Your Application
Testing your Eclipse-assisted application on your Tomcat server is very easy. Simply secondary-click your project's WebContents folder, and choose "Run On Server" from the "Run As" menu to deploy the application to the server of your choice.