views:

227

answers:

2

Hi, I check out the Mojarra JSF 2.0 helloworld sample from here (just enter guest as username). I import it as maven project to eclipse (v 3.5) with a tomcat 6 server. I have the mojarra dependencies for running JSF 2.0 inside a servlet container.

When i package it and because the jsf dependencies have compile scope, these jar are already in WEB-INF/lib. Then i deploy it into a fresh tomcat instance, it works without complain about the ClassNotFoundException.

My problem is i cannot run the project in eclipse without put these jar to the eclipse's tomcat instance.

Is there anything that i've done it wrong ?

A: 

I have the mojarra dependencies for running JSF 2.0 inside a servlet container.

Do you mean that you modified the dependencies of the provided pom as suggested in the comments:

<dependencies>
    <dependency>
        <groupId>javax.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.0</version>
        <scope>provided</scope>
    </dependency>

    <!--
      Uncomment these dependencies and comment out the one above to use
      a simple servlet container instead of a Java EE Application Server
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>[2.0.1,)</version>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>[2.0.1,)</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.1</version>
        <scope>provided</scope>
    </dependency>
     <dependency>
         <groupId>javax.servlet.jsp.jstl</groupId>
         <artifactId>jstl-api</artifactId>
         <version>1.2</version>
     </dependency>
    <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>jstl-impl</artifactId>
        <version>1.2</version>
    </dependency>
    -->

</dependencies>

Can you confirm this? Actually, showing the modified pom might help.

When i use the "run on server" it always say "Cannot found the javax.faces.web.FacesServlet

I guess you meant javax.faces.webapp.FacesServlet. It is definitely in the jsf-api.jar. And putting jsf-api.jar and jsf-impl.jar into the WEB-INF/lib should also work. You're using m2eclipse right?

But when deployed to another tomcat instance(without the mojarra jars) it works fine.

Do you mean outside Eclipse? And without putting the Mojarra jars in Tomcat's lib folder?

Pascal Thivent
Yes, i uncomment these dependencies. But in order to run it inside eclipe, i have to put the mojarra jar into tomcat lib folder.When i package it and because the jsf dependencies have compile scope, these jar are already in WEB-INF/lib. Then i deploy it into a fresh tomcat instance, it works without complain about the ClassNotFoundException.My problem is i cannot run the project in eclipse without put these jar to the eclipse's tomcat instance.
robinmag
@robinmag: I'll try to reproduce later. Sounds weird.
Pascal Thivent
@robinmag: Couldn't reproduce...
Pascal Thivent
A: 

I have resolved it. It is from maven classpath problem not from JSF.

If anyone encounters this, simply right click on your project, then choose "Java EE Module dependencies" then ensure the "Maven dependencies" is checked. Restart your server, maybe you must reload your project (close and reopen) as well.

Hope that help.

robinmag
I wouldn't call that a *Maven Classpath problem* but an Eclipse misconfiguration related issue: if you want to have your project dependencies managed by Maven, your Eclipse project needs to be properly configured... Personally, I prefer creating Maven projects on the command line and then use **Import... > Existing Maven Projects**. It just works, no surprises.
Pascal Thivent