How to run a Maven Project In Tomcat From Eclipse

Using the Maven Eclipse Integration plugin

I you are experiencing problems I’ve found it helpful to try the command line tool mvn for debugging. As a rule of thumb, if it builds without errors command line, then you can run it in Eclipse (but tomcat has problems also, so you might need to clean work directory and clear caches every once in a while).

Other than that I really recommend using the Maven Eclipse Integration plugin! I use the version from Sonatypes plugin repo http://m2eclipse.sonatype.org/sites/m2e. There is a newer integration on the eclipse repo, but it works differently and I have not yet had time to investigate it’s uses yet.

If your project is modular, it may help to setup the root project as a simple project (no Java , no Java EE). Then import the sub-projects as simple Java projects (again no Java EE). You can still activate dependency management and run the build targets through the project.

Import modules

You only need to select the submodules required by your targeted project(s) by dependencies.

Select dependencies to include as sub projects

For any project that builds war files activate facets for java ee and configure context root under further configuration available (this can only be done once, why the option is missing in the screenshot, so do it right).

Select your decired facets

Then setup deployment assembly for your facated projects. All sibling projects (active in you workspace) should be added to deployment assembly and you also need to add the build path entry for maven dependencies to the deployment assembly. Once this is set up you can use the Run on server directive to boot your web apps.

Setup deployment assembly

I find it useful to always stay in pure java mode when coding maven projects. Any smart views in Eclipse only obscures what happens behind the scene, you get access to the specific editors by activating facated projects anyway!

Leave a Comment