Eclipse / Maven / Tomcat
For those Java web application developers who use the fairly standard combination of Eclipse as an IDE and Maven as a build lifecycle / dependency management tool, a really nice feature of Eclipse is that it enables you to deploy your project to embedded servlet containers (e.g. Tomcat / Jetty). This takes the headache out of building and deploying to a standalone servlet container by building the package with Maven and then copying it across every time you make a change. It also makes debugging easier as you can set breakpoints and test in Eclipse itself rather than having to wire up a remote debugger.
The difficulty is that that getting projects to work like this in Eclipse can be a bit of a black art. Here is how I usually get Maven webapp projects set up in Eclipse such that they can be deployed to a Tomcat container.
These instructions are for Eclipse 3.6 (Helios).
- At the command line, change to the project directory containing its pom.xml file.
- Create a Maven eclipse project using the plugin:
> mvn -Dwtpversion=2.0 eclipse:eclipse
- Import the project into Eclipse: File -> Existing project into workspace -> select project directory.
- Right click on the new project -> Maven -> Enable dependency management
- Now, to get the Maven dependency management set up to package of the jar files referenced by the project pom.xml file into the WEB-INF/lib directory of your project package, edit the [project-directory]/.settings/org.eclipse.wst.common.component file and add the following lines:
consumes
- Now refresh the project, add it to your Tomcat server instance: Windows -> Show view -> Other -> Server -> Servers – then right click your server instance and select ‘add and remove’, then select your project.
This should get you up and running.