开发者

jsf 2 and maven with eclipse "run on server"

开发者 https://www.devze.com 2023-01-10 04:27 出处:网络
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

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 ?


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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消