Search code examples
jsfmavenrichfacespom.xmlmyfaces

Pom Dependency in a JSF project with Richfaces and MyFaces


I want to build a JSF project with MAVEN. I tried to add the all dependencies i needed. Each time I get the errors.

<dependencies>
    <dependency>
        <groupId>org.richfaces</groupId>
        <artifactId>richfaces-bom</artifactId>
        <type>pom</type>
        <version>4.2.2.Final</version>
    </dependency>
    <dependency>
        <groupId>org.apache.myfaces.core</groupId>
        <artifactId>myfaces-impl</artifactId>
        <version>2.0.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.myfaces.core</groupId>
        <artifactId>myfaces-api</artifactId>
        <version>2.0.2</version>
        <scope>compile</scope>
    </dependency>

</dependencies>

What should I add to this POM so that my project works as a real JSF project?

P.S I added the right richfaces dependencies. I got deploy problems on websphere like.

Caused by: javax.faces.FacesException: java.lang.UnsupportedOperationException
    at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:387)
    at com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated(WebApp.java:1651)
    at com.ibm.ws.webcontainer.webapp.WebAppImpl.initialize(WebAppImpl.java:410)
    at com.ibm.ws.webcontainer.webapp.WebGroupImpl.addWebApplication(WebGroupImpl.java:88)
    at com.ibm.ws.webcontainer.VirtualHostImpl.addWebApplication(VirtualHostImpl.java:169)
    ... 17 more
Caused by: java.lang.UnsupportedOperationException
    at com.sun.faces.config.ConfigureListener$ApplicationMap.entrySet(ConfigureListener.java:1948)

Solution

  • The Richfaces dependency you are using is just a bom - it lists a set of compatible "real" dependencies and should be used in the dependencyManagement section of your pom:

      <dependencyManagement>
        <dependencies>
          <dependency>
            <groupId>org.richfaces</groupId>
            <artifactId>richfaces-bom</artifactId>
            <version>4.2.2.Final</version>
            <type>pom</type>
          </dependency>
        </dependencies>
    </dependencyManagement>
    

    In the dependencies, you should have the implementation, like this:

    <dependencies>
      <dependency>
        <groupId>org.richfaces.ui</groupId>
        <artifactId>richfaces-components-ui</artifactId>
        <!--version>4.2.2.Final</version-->
      </dependency>
    
      <dependency>
        <groupId>org.richfaces.core</groupId>
        <artifactId>richfaces-core-impl</artifactId>
        <!--version>4.2.2.Final</version-->
      </dependency>
    <dependencies>
    

    The version element of the dependencies is redundant, if you are using the bom. You are better off removing it, as you may unwillingly overrride the bom setting.

    EDIT: the error you are getting looks like a configuration issue to me. Not sure what may have caused it. My advice is to start with a working webapp example and then add additional dependendcies. My favorite way is to let maven geneare a webapp from archetype:

    mvn archetype:generate

    you will then see a long list of possibl archetypes. Try something with a JSF in it, like jsf-weld-servlet-webapp or weld-jsf-jee or richfaces-archetype-simpleapp. These are known to work, and you can sample the pom and the rest of the project to see what may be missing.