How to add RichFaces 4.x to maven based project

This article will walk you through the steps needed to use RichFaces in a Maven build environment.

 

The first step is to take a look at this article to configure Maven for using JBoss repository.

Base dependencies

     First you should add richfaces-components-bom to your dependency-management section of your pom.xml. That should be done in order to have all the runtime dependencies with versions for the specified release.

A note on release naming
The shorthand name for current milestone release is 4.1.0.Final; this is what you'll see in many locations primarily meant to be read by humans (e.g. the download pages.) The official name for the release is 4.1.0.Final, as according to JBoss project versioning conventions final releases not required to be marked with timestamps. The inclusion of the date of the release in the release qualifier used only for milestones  and helps to ensure proper release ordering as specified by the OSGi specification. The official name appears in distributions zips, jar manifests, Maven pom files, and in Maven repository URLs. So it should be included like shown at snippet below:

 

    <properties>
        <org.richfaces.bom.version>4.1.0.Final</org.richfaces.bom.version>
        ...
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.richfaces</groupId>
                <artifactId>richfaces-bom</artifactId>
                <version>${org.richfaces.bom.version}</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
            ...
        </dependencies>
    </dependencyManagement>


Whats a BOM

To understand the "Bill of Materials" (BOM) concept more check out:

 

In short bom's are maven pom.xml files that all runtime dependencies with versions listed for a concrete module.  So by importing this, you are importing the required versions, and dependencies to use RichFaces.

 

RichFaces Dependencies

 

Next you will need to add richfaces-components-ui dependency to your project dependencies sections.

 

 

    <dependency>
        <groupId>org.richfaces.ui</groupId>
        <artifactId>richfaces-components-ui</artifactId>
    </dependency>
    <dependency>
        <groupId>org.richfaces.core</groupId>
        <artifactId>richfaces-core-impl</artifactId>
    </dependency>

 

CDK annotations dependency

 

<dependency>
     <groupId>org.richfaces.cdk</groupId>
     <artifactId>annotations</artifactId>
     <scope>provided</scope>
</dependency>

This dependency is compile time and only needed if you are creating/accessing some RF components instances in your application actions/listeners in order to define CDK annotations.

 

 

That's all for Milestone 2 and later versions - all the other dependencies will be fetched transitivelly.

 

Note as you could see from the last two snippets - you do not need to specify the version for the dependency. It's defined in BOM file from above. All the other runtime dependencies like JSF artifacts, EL, Servlet and other(you could check in bom file after fetching) also has version specified there That's the version which we are defining for the release. So you could remove the versions in your existent POM for those artifacts to use ones under which we officially released - but it's not a requirement. Your application could re-define them with any other supported version.

 

RichFaces samples - Import and Deployment in Jboss Tools
  • Checkout sources from https://svn.jboss.org/repos/richfaces/trunk/examples/
  • Execute mvn eclipse:eclipse from the root folder of example.
    • some examples supports different profiles(e.g. richfaces-showcase and core demo supports jee6 build for Jboss or gae for GAE compatible build). So in order to import sample for JEE 6 deployment add -P jee6 to the command line.
  • Import project as "Existent project" using Eclipse import project wizard
  • Add M2_REPO variable to Eclipse Class Path variables and point it to your local repository.
  • After project successfully built - add it to server from server view
  • run server and check application in browser.