This tutorial will allow you to use Jsf with Liferay on tomcat .
Important point: Tomcat is not natively a Java EE application server but a servlet container. It does not contain the libraries needed to use JSF. So we have to add them manually.
The two JSF JARs needed are jsf-api.jar and jsp-impl.jar. We will use Mojarra as JSF implementation.
There are two ways to use JSF on your Liferay projects. Either by adding it to the application as dependencies (the project classpath) or by adding it in the global context of Tomcat (tomcat/lib/ext) and declaring it as “provided”.
Both ways will be presented below.
Table of contents
1- Include the JARs in the application context classpath
The first way to use JSF with Liferay is to include the two needed dependencies (jsf-api.jar and jsf-impl.jar) in the project classpath (WEB-INF/lib). To do so, add the following code to all your Liferay projects pom.xml.
1 2 3 4 5 6 7 8 9 10 |
<dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-api</artifactId> <version>2.2.9</version> </dependency> <dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-impl</artifactId> <version>2.2.9</version> </dependency> |
2- Include the JARs in Tomcat global classpath
The second way to use JSF with Liferay is to make the JARs provided by the Tomcat server. Some changes of the jsf–impl.jar are to do because of the Mojarra ConfigureListner. Follow these instructions :
- Download jsf-api.jar and jsp-impl.jar (click on download (JAR)) and save it on your computer
- Copy the two JARs to the $LIFERAY_HOME/tomcat/lib/ext folder
- Open a terminal window (Press “windows + r” and tape “cmd” a click “Enter“)
- Navigate to your $LIFERAY_HOME/tomcat/lib/ext
1cd $LIFERAY_HOME/tomcat/lib/ext - Create a temporary folder named jsf-impl
1mkdir jsf-impl - Navigate to the created folder
1cd jsf-impl - Extract the jsf-impl.jar into the created folder (Be sure to have the path to the Java JDK /bin in the “PATH” environment variable)
1jar xf ../jsf-impl-2.2.9.jar - Open the file “jsf_core.tld” located in “jsf-impl/META-INF” and remove the following lines (from 87 to 89)
123<listener><listener-class>com.sun.faces.config.ConfigureListener</listener-class></listener> - Save and close the modified file
- Remove the Mojarra servlet container initializer file “javax.servlet.ServletContainerInitializer” located under “jsf-impl-2.2.9/META-INF/services”
1rm META-INF/services/javax.servlet.ServletContainerInitializer - Create a new archive
1jar cf ../jsf-impl-2.2.9.jar META-INF/ com/ - Remove the temporary folder
12cd ../rm -rf jsf-impl/ - Follow one of the two following sub-steps
a. Add the liferay-faces-init.jar dependency in each Liferay JSF project by adding the following code to each pom.xml :
12345<dependency><groupId>com.liferay.faces</groupId><artifactId>liferay-faces-init</artifactId><version>3.1.3-ga4</version></dependency>
123<listener><listener-class>com.sun.faces.config.ConfigureListener</listener-class></listener> - Declare the jsf-api and jsf-impl dependencies as provided in each JSF project pom.xml:
123456789101112<dependency><groupId>com.sun.faces</groupId><artifactId>jsf-api</artifactId><version>2.2.9</version><scope>provided</scope></dependency><dependency><groupId>com.sun.faces</groupId><artifactId>jsf-impl</artifactId><version>2.2.9</version><scope>provided</scope></dependency>