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 (4.0.0 ALPHA2 and later)

     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.0.0.M1; this is what you'll see in many locations primarily meant to be read by humans (e.g. the download pages.) However, the official name for the release is 4.0.0.20100715-M1, a name which follows the JBoss project versioning conventions for projects that issue milestone releases. The inclusion of the date of the release in the release qualifier helps 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>
        <!-- for Alhpa versions it was just 'ALPHA2' -->  
        <org.richfaces.ui.version>4.0.0.20100715-M1</org.richfaces.ui.version>
        ...
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.richfaces.ui</groupId>
                <artifactId>richfaces-components-bom</artifactId>
                <version>${org.richfaces.ui.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>

 

Logger Dependency

sl4j-api added transitivelly but implementation should be added also by end-developer. For example sl4j-log4j12:

 

     <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </dependency> 

Or any other impl.

 

CDK annotations dependency

 

<dependency>
     <groupId>org.richfaces.cdk</groupId>
     <artifactId>annotations</artifactId>
     <scope>provided</scope>
     <version>4.0.0-SNAPSHOT</version>
</dependency>

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

 

 

That's all for ALPHA 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.