Build and Deploy maven project with embedded tomcat

Build and Deploy maven project with embedded tomcat

Build and Deploy maven project with embedded tomcat

//: # ()

You can generate, build and run Java web apps without the need of IDE like Eclipse or NetBeans.

You can do this simply from the command line with maven.

You don't need tomcat installed for this. You just need Java and Maven installations.

Generate the Web app with maven-archetype-webapp

mvn archetype:generate -DgroupId=com.metamug -DartifactId=mywebapp -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

This will generate a folder mywebapp

Build the project

Enter inside the project with

  cd mywebapp

Once inside the webapp. you can run the following to verify if the webapp has generated proper maven project.

mvn compile

But wait, the whole point of writing this article is to fix the issues in the generated webapp. Only after we fix those issues, we can run the project.

Change the tomcat plugin to tomcat7 in pom.xml

The tomcat plugin supported by maven is tomcat7. So it must be updated in the plugin section of pom.xml


Update web.xml version.

The web.xml generated by maven-archetype-webapp is old and doesn't allow expression language to work. This can't be fixed even if you add maven dependency javax.el-api

The generated web.xml uses servlet API 2.3 This web.xml file should be replaced

 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "" >

  <display-name>Archetype Created Web Application</display-name>

Change the xsd version from 2.3 to 3.0.

<web-app xmlns=""

  <display-name>Archetype Created Web Application</display-name>

Run the application

Finally, run the application with the tomcat7 plugin.

    mvn clean install tomcat7:run

You can access the application in the browser with


The war is bundled and deployed on tomcat.

Add the JSTL Dependency to pom.xml


To identify Web API Classes add javax dependency


After adding the dependency you rerun with

mvn clean install tomcat7: run

It rebuilds the application and deploys the war file again.

You can edit the generated index.jsp and you will see the changes to the browser. The below JSP file uses both JSTL and Expression Language to confirm the configuration is done correctly.

<%@ taglib uri = "" prefix = "c" %>

 <c:set var="x" value="5" />
 <h4> The value of x is: <c:out value="${x}" /> </h4>
Icon For Arrow-up