How do I run a maven web application in Tomcat from Eclipse?
Author: Deron Eriksson
Description: This tutorial describes how to run a maven web application project in Tomcat from Eclipse.
Tutorial created using: Windows Vista || JDK 1.6.0_04 || Eclipse Web Tools Platform 2.0.1 (Eclipse 3.3.1) || Tomcat 6.0.14


Page:    1 2 >

This tutorial will demonstrate how we can run a maven-based web application in TomcatSW via EclipseSW.

In another tutorial, I demonstrated how we could create an Eclipse User Library to represent a set of Tomcat jarW files. In one other tutorial, I showed how we could have mavenSW add this user library (set of jar files) to a project's .classpath file by referencing the maven-eclipse-plugin in the project's pom.xml file and adding a classpathContainer entry for the user library (which I called TOMCAT_6.0.14_LIBRARY). Adding the Tomcat user library to the project's classpathW allows us to now debug/run the project in Tomcat via Eclipse.

So, let's get started. First of all, I need to add a Context entry to my Tomcat's server.xml file for the "mywebapp" project. In Eclipse, I have a "_stuff" project that contains a link to my Tomcat's server.xml file for convenience. So, I'll double-click the server.xml link to open up the server.xml file in Eclipse's XMLW editor.

Eclipse Navigator View

I'll add the following Context element to my Tomcat server.xml file. The docBase attribute specifies my web context directory (ie, web, public_html, webapp, etc..) for my project. The path attribute specifies the path that is used to hit the project via a web browser (ie, http://localhost:8080/mywebapp).

<Context docBase="C:\dev\workspace\mywebapp\src\main\webapp" path="/mywebapp" reloadable="true"/>

The server.xml file is shown below. Notice that the <Context> element is within the <Host> element.

server.xml in Eclipse XML Editor

(Continued on page 2)

Page:    1 2 >