Maven Tomcat 9

Posted onby admin
The installation of Apache Maven is a simple process of extracting the archive and adding the `bin` folder with the `mvn` command to the `PATH`.

Detailed steps are:

How to Run Web Application in Tomcat Maven Plugin, Run Web Application in Tomcat Maven Plugin, Using an Embedded Tomcat with Maven tomcat plugin, Run Maven Web Application in Tomcat Maven Plugin Tutorial, How do I run a maven web application in Tomcat Maven Plugin.

  • Ensure JAVA_HOME environment variable is set and points to your JDK installation

  • Extract distribution archive in any directory

  • Dec 16, 2018 Tomcat can be downloaded here (version 9 at the time of this writing). After downloading the archive, it’s prudent to check the file hash to verify the integrity of the downloaded file. Run this command (Mac): openssl dgst -sha512.
  • Feb 12, 2020 mvn archetype:generate -DgroupId=com.baeldung -DartifactId=tomcat-war-deployment -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false This will create a complete web application in the directory tomcat-war-deployment which, if we deploy now and access via the browser, prints hello world!.


Eclipse Maven Tomcat 9

Alternatively use your preferred archive extraction tool.

  • Add the bin directory of the created directory apache-maven-3.8.1 to the PATH environment variable

  • Confirm with mvn -v in a new shell. The result should look similar to

Windows Tips

  • Check environment variable value e.g.
  • Adding to PATH: Add the unpacked distribution’s bin directory to your user PATH environment variable by opening up the system properties (WinKey + Pause), selecting the “Advanced” tab, and the “Environment Variables” button, then adding or selecting the PATH variable in the user variables with the value C:Program Filesapache-maven-3.8.1bin. The same dialog can be used to set JAVA_HOME to the location of your JDK, e.g. C:Program FilesJavajdk1.7.0_51

  • Open a new command prompt (Winkey + R then type cmd) and run mvn -v to verify the installation.

Unix-based Operating System (Linux, Solaris and Mac OS X) Tips

  • Check environment variable value
  • Adding to PATH

PrimeFaces is an open source component library for JavaServer Faces (JSF). It provides a collection of mostly visual components (widgets) that can be used by JSF programmers to build the UI for a web application. An overview of these widgets can be found at the PrimeFaces showcase.

Apache Tomcat, is an open-source web server developed by the Apache Software Foundation. It implements several Java EE specifications and provides a “pure Java” HTTP web server environment for Java code to run in. Tomcat is released under Apache License 2.0 and is open-source software.

The following post illustrates a basic example in which we will configure, build and run a Hello World PrimeFaces example using Tomcat and Maven.

Tools used:

  • JSF 2.2
  • PrimeFaces 6.1
  • Tomcat 7
  • Maven 3.5
Eclipse maven tomcat 910.0.0-M10Cached

The code is built and run using Maven. Specified below is the Maven POM file which contains the needed dependencies for JSF and PrimeFaces.

Maven Run Embedded Tomcat 9

In order to run the Hello World PrimeFaces application, a servlet container is needed and in this example, the Apache Tomcat implementation will be used. The deployment of the code and application server will be fully automated using the tomcat7-maven-plugin.

The Tomcat plugin takes as input two configuration parameters so that the HTTP listener port is set to “9090” and the context path is set to “codenotfound”.

The remaining code of the example is identical to a previous PrimeFaces Hello World example running on Jetty. Feel free to check it out if you would like to know more details.

In order to run the above example open a command prompt and execute following Maven command:

Maven will download the needed dependencies, compile the code and start a Tomcat instance on which the web application will be deployed. The result should be the following startup trace ending with: 'Starting ProtocolHandler'.

Open a web browser and enter following URL: http://localhost:9090/codenotfound/. The below page should be displayed:


Enter a first and last name and press the Submit button. A pop-up dialog will be shown with a greeting message.

If you would like to run the above code sample you can get the full source code here.

Maven Tomcat 9 Dependency

This concludes the PrimeFaces on Apache Tomcat example. If you found this post helpful or have any questions or remarks, please leave a comment.