
Adding Maven dependencies
The archetype that we selected for the project does not include some of the dependencies required for a JEE web project. Therefore, you might see error markers in index.jsp. We will fix this by adding dependencies for the JEE libraries:
- With pom.xml open in the editor, click on the Dependencies tab.
- Click the Add button. This opens the Select Dependency dialog.
- In the filter box, type javax.servlet (we want to use servlet APIs in the project).
- Select the latest version of the API and click the OK button.

Figure 2.32: Adding servlet API dependency
However, we need JAR files for servlet APIs only at the compile time; at runtime, these APIs are provided by Tomcat. We can indicate this by specifying the scope of the dependency; in this case, setting it to provided, which tells Maven to evaluate this dependency for compilation only and not to package it in the WAR file. See http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html for more information on dependency scopes.
- To set scope of the dependency, select dependency from the Dependencies tab of the POM editor.
- Click the Properties button. Then, select the provided scope from the drop-down list:

Figure 2.33: Setting the Maven dependency scope
- Now we need to add dependencies for JSF APIs and their implementation. Click the Add button again and type jsf in the search box.
- From the list, select jsf-api with Group Id com.sun.faces and click the OK button:

Figure 2.34: Adding Maven dependencies for JSF
- Similarly, add a dependency for jsf-impl with Group Id com.sun.faces. The dependencies section in your pom.xml should look as follows:
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-api</artifactId> <version>2.2.16</version> </dependency> <dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-impl</artifactId> <version>2.2.16</version> </dependency> </dependencies>
If Tomcat throws an exception for not finding javax.faces.webapp.FacesServlet
then you may have to download jsf-api-2.2.16.jar (http://central.maven.org/maven2/com/sun/faces/jsf-impl/2.2.16/jsf-impl-2.2.16.jar) and jsf-impl-2.2.16.jar (http://central.maven.org/maven2/com/sun/faces/jsf-impl/2.2.16/jsf-impl-2.2.16.jar) and copy them to the <tomcat-install-folder>/lib folder.