Unable to initialize FacesServlet in Tomcat 7 - ClassNotFoundException

让人想犯罪 __ 提交于 2019-12-09 12:28:15

问题


I am trying out a simple hello world app in JSF but based on the exception thrown by tomcat on start I see that FacesServlet is not getting initialized. I have the required jar files myfaces-api, bundle, impl and commons beanutils, codec, collections, digester, logging. Apart from that I read in another question on SO that I would also required jsf-api.jar and jsf-impl.jar which I also placed in WEB-INF/lib and added to build path

Still no luck. I am developing on Ubuntu, using Eclipse and Tomcat 7

Here is my web.xml

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>Doom</display-name>
  <display-name>JavaServerFaces</display-name>

    <!-- Change to "Production" when you are ready to deploy -->
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>

    <!-- Welcome page -->
    <welcome-file-list>
        <welcome-file>faces/welcome.xhtml</welcome-file>
    </welcome-file-list>

    <!-- JSF mapping -->
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <!-- Map these files with JSF -->
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.faces</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
</web-app>

This is the exception

java.lang.ClassNotFoundException: javax.faces.webapp.FacesServlet
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:397)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1062)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1010)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4935)
    at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5262)
    at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5257)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)

回答1:


After 2 weeks i found the answer. very simply as always in the end. you need to copy both

jsf-api.jar
jsf-impl.jar

To the tomcat lib. having it in the project lib does not seem to work.




回答2:


I had the same problem, working with Eclipse Juno and Tomcat 7 - Tomee 1.6.0.

I want to use mojarra 2.0.3 and I've found many problems in server deployment. I've solved it deleting myfaces-*.jar in Tomcat lib; then adding mojarra lib in Tomcat directory and then starting server. Now all it's OK, it's running.

After many configurations changes, I've seen that what really works it's the library installed in Tomcat directory, directly ignoring Eclipse configurations. maybe a bug?

Finally I've solved my problem manually changing the Tomcat library on my own. I don't think that it will be a problem in the future anymore.




回答3:


This dependency contain required libraries and may fix your problem

'org.glassfish:javax.faces:2.3.0'


来源:https://stackoverflow.com/questions/18030543/unable-to-initialize-facesservlet-in-tomcat-7-classnotfoundexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!