January 4, 2016

JSF - PrimeFaces Apache Tomcat Example

primefaces logo
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.0
  • Tomcat 7
  • Maven 3

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

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'.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi=""


    <name>JSF - PrimeFaces Apache Tomcat Example</name>




        <!-- Servlet -->
        <!-- JSF -->
        <!-- PrimeFaces -->


The remaining code of the example is identical to the PrimeFaces Hello World example detailed in this post. 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:
mvn tomcat7:run

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'.
[INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ jsf-primefaces-tomcat ---
[INFO] Running war on http://localhost:9090/codenotfound
[INFO] Using existing Tomcat server configuration at c:\code\st\jsf-primefaces\jsf-primefaces-tomcat\target\tomcat
[INFO] create webapp with contextPath: /codenotfound
okt 29, 2016 7:16:14 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-9090"]
okt 29, 2016 7:16:14 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Tomcat
okt 29, 2016 7:16:14 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.47
okt 29, 2016 7:16:16 AM com.sun.faces.config.ConfigureListener contextInitialized
INFO: Initializing Mojarra 2.2.13 ( 20160203-1910 unable to get svn info) for context '/codenotfound'
okt 29, 2016 7:16:16 AM com.sun.faces.spi.InjectionProviderFactory createInstance
INFO: JSF1048: PostConstruct/PreDestroy annotations present.  ManagedBeans methods marked with these annotations will have said annotations processed.
okt 29, 2016 7:16:16 AM org.primefaces.webapp.PostConstructApplicationEventListener processEvent
INFO: Running on PrimeFaces 6.0
okt 29, 2016 7:16:16 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-9090"]

Open a web browser and enter following URL: http://localhost:9090/codenotfound/. The below page should be displayed:
primefaces apache tomcat hello world example

Enter a first and last name and press the Submit button. A pop-up dialog will be shown with a greeting message.
primefaces apache tomcat example hello world greeting

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

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