How To Run Embedded Tomcat with Maven

4 years ago by in How To, Maven, Tomcat, Web Application Tagged: , , , , ,

Java web application require a web container, such as Tomcat (homepage), on which these can run. Installing and configure a web container on each developing machine may be time consuming. Furthermore, other developers need to manage the dependencies manually if they want to run the web application.

Maven has a tomcat plugin that allows us to run an embedded tomcat instance without the need of installing a local tomcat server.


Please note that this example makes use version 7 of Tomcat. Please update where necessary if using another version of Tomcat.

All code listed below is available at: To Run Embedded Tomcat with Maven/. Most of the examples will not contain the whole code and may omit fragments which are not relevant to the example being discussed. The readers can download or view all code from the above link.

Include the Tomcat Maven Plugin as shown in the following POM example.

<project xmlns="" 
  <name>How To Run Embedded Tomcat with Maven</name>
    <name>Java Creed</name>




Please note that the above configuration will start the embedded Tomcat instance on port 9090. You can change the port as required.

Build the project

mvn clean install

Start the embedded Tomcat server.

mvn tomcat7:run

This will produce something similar to the following.

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building How To Run Embedded Tomcat with Maven 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) @ how-to-run-embedded-tomcat-with-maven >>>
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ how-to-run-embedded-tomcat-with-maven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ how-to-run-embedded-tomcat-with-maven ---
[INFO] Nothing to compile - all classes are up to date
[INFO] <<< tomcat7-maven-plugin:2.2:run (default-cli) @ how-to-run-embedded-tomcat-with-maven <<<
[INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ how-to-run-embedded-tomcat-with-maven ---
[INFO] Running war on http://localhost:9090/
[INFO] Creating Tomcat server configuration at C:\JavaCreed\examples\maven\How To Run Embedded Tomcat with Maven\target\tomcat
[INFO] create webapp with contextPath:
Mar 20, 2014 4:00:05 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-9090"]
Mar 20, 2014 4:00:05 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Tomcat
Mar 20, 2014 4:00:05 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.47
Mar 20, 2014 4:00:07 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-9090"]

Please note that when executed for the first time, Maven may download any missing components and thus may produce more output than that shown above.

Open the browser.


You should see something similar to the following

Embedded Tomcat

Embedded Tomcat

We managed to run a Java web application without having to install a web server such as Tomcat.

Albert Attard

Albert Attard is a Java passionate and technical lead at a research group. You can find him on . Over the past years Albert worked on various Java projects including traditional server/client applications, modular applications, large data handling applications and concurrent data manipulation applications to name a few. He has a BSc degree from the University of London (Homepage) and an MSc Information Security with the same university. His MSc thesis (Book) received the 2012 award (Website).

10 Responses to “How To Run Embedded Tomcat with Maven”

July 9, 2014 Reply

Nice post.. Thanks!

September 6, 2014 Reply

Thank you!

December 14, 2015 Reply

Thanks a lot, you saved my day!

December 15, 2015 Reply

how do you configure the memory in here; say I want to run with a larger heap size of 1024m

December 15, 2015 Reply

How do you change the memory settings? I don’t want to run with the default settings?

Albert Attard Albert Attard
January 5, 2016 Reply


Never did that myself. I suggest you have a look at the plugin simple website: for more information about how to further customise this plugin.


December 29, 2015 Reply

I added the same dependency but still tomcat is not starting. I am getting 404 error while I enter the url mentioned http://localhost:9090/hello

Albert Attard Albert Attard
January 5, 2016 Reply


There can be several issues.

  1. Check that the path http://localhost:9090 (without the application context name hello) works
  2. Make sure that the application context name is actually hello
  3. Make sure that the application has a default/welcome page

Hope this helps you solve the problem.

Tribhuwan Kumar Yadav
May 27, 2016 Reply

Nice post! I have been wondering what’s the use of tomcat7:run, when already we have tomcat configured….and able to run the application on server…

Rocki Docki
March 13, 2018 Reply

Thanx, still helpfull in 2018!

Leave a Comment

Time limit is exhausted. Please reload the CAPTCHA.