It's been a long time since my last post, for this series of tutorials. Its time to resume and add new features on our simple project. As I have mentioned in previous posts, this series of posts is targeting mostly Maven and JavaEE7 newcomers, I welcome any questions or comments (and fixes) on the contents below. I promise I will try to keep up with the updates.
Git tag for this post?
What has changed from the previous post?
- Some comments and fixes on the code from readers have already been integrated.Thank you very much all for your tome.
- I have updated the Wildfly Application Server version from 8.1 to 8.2, so all the examples and code runs under the new server.
- I have also updated the versions of the Arquillian BOM (s), to the latest version which is now 1.1.7.Final
- I have also added a property under the sample-parent project that indicates the path that the various maven modules will download and use Wildfly server, automatically so that you don't have to download it on your own. The server will be automatically downloaded and extracted to the predefined path, as soon as you try to execute one of the unit tests from the previous posts (sample-services module)
Adding a JSF enabled war Maven Module on our ear
Eventually our project structure already featured a war (see sample-web) maven module. So there is no extra module introduced rather than changes on the existing pom.xml files of the parent and the module itself.
Step 1 changes on web.xml
Our application server is already bundled with the required libraries and settings in order to support applications that make use of the JSF 2.2 specification. Wildfly bundles Mojarra 2.2.8. What we have to do is just update some configuration descriptors (eventually only one). The most important is web.xml which now looks like this.
Step 2 Packaging of war and the skinny war issue
Our war module, is following a packaging scheme called skinny war. Please read the following page from the Apache maven war plugin. To cut a long story short, in order to reduce the overall size of our deploy able (ear), we package all the required libraries under a predefined folder on the ear level, usually is called \lib and we don't include libraries under the war's WEB-INF\lib folder. The only thing you need to do, is add those dependencies of your war to the ear level. Despite the fact that the overall 'hack' does not feel very maven like, it works if you follow the proposed configuration, but there are cases that skinny war packaging wont work. One of these is usually for JSF based JavaEE web applications where the implementation of the JSF widget engine should be packaged within the war's WEB-INF\lib.
For our sample project, I am using the excellent and free Primefaces library, which I highly recommend for your next JSF based project. So I need to define a dependency on my war module for the primefaces jar but by pass the skinny war mechanism only for this jar, so that it is packaged in the right place. This is how we do it.
Step 3 Add some jsf love, a managed bean and an xhtml page with the appropriate tags.
Our code is just a small table, and a couple of tags from Primefaces. If you think that you need to read more about JSF 2.X please have a look on the following links
- JSF 2.2 tutorial by one of the JSF gods (BalusC)
- Primefaces documentation
- Primefaces Show Case
- The JavaEE tutorial - JSF 2.2 from Oracle
- JSF 2.2 examples
Step 4 Package and deploy to a running server.
Start your wildfly (you are expected to have one under your project-base dir and the subfolder servers
and then under the sample-parent project type.
mvn clean install -Ph2
You should have your demo JSF 2.2 enabled demo app, on http://localhost:8080/sample-web/ and see something like the following.
That's all, this will give you a simple start in order to expand on something more than a demo!
As always you will find the complete - example under tag post8 .