Skip to content
Related Articles

Related Articles

Improve Article

Embedding Tomcat Server in Maven Project

  • Difficulty Level : Medium
  • Last Updated : 15 Nov, 2018

Today, developing an application using different servers depending on the environment which is to be used is really a tricky job. Applications may work fine in one server and may end up not working properly on the other server which is a problematic one. What if the developer had a privilege to use or configure a server for a development purpose without even downloading the same, which really reduces a lot of manual work and hence, time-saving can be noticed.

Tomcat Server: Tomcat is one of the best web server and an open source Java Servlet container developed by Apache Software Foundation (ASF), which is used by many developers for their project works. It has sublimed to such a greater extent just because of its classicality and its speed and implements J2EE specifications which majorly includes servlets, JSP and expression languages. With the availability of these vital features, the Tomcat server is still one of the best web servers available in the market.

Consider a scenario of using Tomcat Server without even downloading and installing it. Yes, this is really possible and is very easy to handle through the use of powerful tool “Maven“. Maven provides a graceful plugin called tomcat7-maven-plugin through which the Tomcat Web Server can be embedded seamlessly into a Maven project.

Maven: Maven is one of the most famous build automation used for Java projects. The 2 key aspects of the Maven are, first, how the project is built/developed and the second is dependencies associated in the Java project which uses Maven build tool. The required libraries in the form of dependencies will be downloaded by the Maven tool from the central repository and the same will be persisted in the local cache. Maven is developed based on the plugin-based architecture and hence makes it easier to control the project through the utilization of standard inputs.

Steps to configure Tomcat Server in a Maven Project:

  1. Create a simple maven project as shown below:

    maven project creation

  2. Open the pom.xml file and add the below-mentioned plugin entry.




    <plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.2</version>
    <configuration>
    <port>9090</port>
    </configuration> </plugin>
  3. Now lets just start using it. Run the command mvn clean install in order to compile the project with the tomcat plugin.

  4. Now run the application by executing the command mvn tomcat7:run, which will start the tomcat server.

  5. Open the browser and enter the URL: http://localhost:9090/EmbeddedTomcat

Go Premium (An Ad Free Experience with many more features)

My Personal Notes arrow_drop_up
Recommended Articles
Page :