table of contents

Tutorial: Using Tomcat 6 with MyEclipse

This page is no longer being actively maintained. For up-to-date info on Tomcat 6 and 7 for use with Eclipse, please see http://www.coreservlets.com/Apache-Tomcat-Tutorial/

Executive Summary

The time it takes to download an IDE and learn the barebones basics of use will be very quickly recouped by the savings in development, debugging, and deployment times. I personally feel that the extra features of MyEclipse more than justify the very small cost vs. the totally free regular Eclipse IDE, but this is definitely a matter of taste, and both versions are widely used. Here is a quick summary of use; see the next sections for details.

  1. Download and install Java from http://java.sun.com/javase/downloads/. I use JDK 1.6.0_14, but any Java 5 or 6 version will work.
  2. Unzip Tomcat. Unzip tomcat-6.0.18-preconfigured.zip into the top level of the C drive.
  3. Install MyEclipse. Download from http://myeclipseide.com/ and run installer.
  4. Tell MyEclipse about Tomcat. Select Window, Preferences, MyEclipse, Servers, Tomcat, Tomcat 6. Click "Enable". Select "Tomcat Home Directory" and hit "Browse". Navigate to the Tomcat installation directory Click Apply & OK.
  5. Run Tomcat. Click on Servers tab at bottom. R-click on Tomcat 6, choose "Run Server". Open http://localhost/ in a browser.
  6. Import and Test a Sample Web App. Grab intro-app-myeclipse.zip, save it, and import it into MyEclipse. Use File, Import, Existing Projects, Select archive file. Then click Browse and navigate to intro-app-myeclipse.zip. Click on Servers tab at bottom. R-click on Tomcat 6, choose "Manage Deployments". Choose intro app. Start Tomcat if not already running. Open http://localhost/intro/ in browser.
  7. Create and Test a new Web App. File, New, Project, MyEclipse, Java Enterprise Projects, Web Project. Deploy and test it as above.

Unzip Tomcat

Unzip tomcat-6.0.18-preconfigured.zip into the top level of the C drive. This should result in C:\apache-tomcat-6.0.18\. This version of Tomcat has the following settings already in place. For details on customizing this configuration, please see the detailed configuration guide.
  • The port is changed from 8080 to 80. This lets you enter URLs of the form http://localhost/... instead of http://localhost:8080/....
    • When you download Tomcat from the Apache site, the port is 8080 in case you already have another server running on port 80.
  • The invoker servlet is enabled. This lets run servlets with a URL of the form http://localhost/appName/servlet/packageName.servletName. That is, the invoker servlet saves you from editing web.xml to give a servlet-mapping to your servlet.
    • When you download Tomcat from the Apache site, the invoker servlet is disabled. You definitely want the invoker servlet disabled on a server used for a deployed application, but having it enabled on your development server is very convenient for quick testing.
  • Tomcat monitors struts-config.xml and faces-config.xml. Whenever either of these files changes, Tomcat reloads the Web application. This saves you from restarting the server when you change these files.
    • If you do not use Struts or JSF, this change will not be beneficial to you. But it does not hurt either way.
  • Directory listings are turned on. If you type a URL ending in / and there is no welcome file, Tomcat shows a directory listing.
    • Directory listings were on by default in previous Tomcat versions. They are not required but are convenient, especially during development.

Install MyEclipse

Go to http://myeclipseide.com/, click on Download, choose the "All in One" installer, and install with all the default settings. Start it and select "Workbench".

Tell MyEclipse about Tomcat

Select Window, Preferences, MyEclipse, Servers, Tomcat, Tomcat 6. Click "Enable". Select "Tomcat Home Directory" and hit "Browse". Navigate to the Tomcat installation directory Click Apply & OK.
MyEclipse Tomcat Path

Also click on the JDK sub-entry under Tomcat and make sure this matches the main Java version you are using. In particular, if you are using Java 6 but the Tomcat JDK refers to Java 5, you will get illegal class file errors when executing servlets.
MyEclipse Tomcat JDK

Run Tomcat

Click on Servers tab at bottom. R-click on Tomcat 6, choose "Run Server". Open http://localhost/ in a browser: you should see the Tomcat home page.
MyEclipse Running Tomcat

Import a Sample App and Test

Grab intro-app-myeclipse.zip, save it, and import it into MyEclipse. Use File, Import, Existing Projects, Select archive file.
MyEclipse Import Project
Click on Servers tab at bottom. R-click on Tomcat 6, choose "Manage Deployments". Choose intro app. Start Tomcat if not already running. Try the following URLs in a browser:

  • http://localhost/intro/ Directory listing showing Hello.html and Hello.jsp.
  • http://localhost/intro/Hello.html Be sure to use an uppercase "H" in "Hello".
  • http://localhost/intro/Hello.jsp Be sure to use an uppercase "H" in "Hello".
  • http://localhost/intro/servlet/HelloServlet HelloServlet via invoker servlet.
  • http://localhost/intro/hi HelloServlet via servlet mapping in web.xml.
  • http://localhost/intro/servlet/coreservlets.HelloServlet2 HelloServlet2 via invoker servlet.
  • http://localhost/intro/hi2 HelloServlet2 via servlet mapping in web.xml.
  • http://localhost/intro/servlet/coreservlets.HelloServlet3 HelloServlet3 via invoker servlet.
  • http://localhost/intro/hi3 HelloServlet3 via servlet mapping in web.xml.

Making New Apps in MyEclipse


  • Make empty project.
    • File, New, Project, MyEclipse, Java Enterprise Projects, Web Project.
    • Give it a name (e.g., "test").
    • Accept all other defaults.
MyEclipse New Project 1
MyEclipse New Project 2
MyEclipse New Project 3

Adding Code to New Apps in MyEclipse


  • WebRoot (often renamed to WebContent).
    Web content (HTML, JavaScript, CSS, JSP, images, etc.) Most people delete the auto-created index.html file.
  • WebRoot/some-subdirectory
    Web content in subdirectory.
  • WebRoot/WEB-INF
    web.xml (used for servlet mappings)
  • WebRoot/WEB-INF/lib
    JAR files specific to application.
  • src
    Unpackaged Java code.
  • src/somePackage
    Java code in somePackage package.
  • Note:
    You can cut/paste or drag/drop existing files into appropriate locations.
MyEclipse New Project 4

Testing New Apps in MyEclipse

Follow same procedure as given in example above with "intro" app: Click on Servers tab at bottom. R-click on Tomcat 6, choose "Manage Deployments". Choose the app. Start Tomcat if not already running. Open http://localhost/appName/ in browser.

More Information

Java

JSF (JavaServer Faces)

Servlets & JSP
Ajax, GWT, & JavaScript

Spring, Hibernate, & JPA

Struts