Unable to initialize FacesServlet in Tomcat 7 - ClassNotFoundException
Asked Answered
E

4

6

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)
Eglantine answered 3/8, 2013 at 7:41 Comment(2)
Adding the javax.faces-2.2.0.jar (from repo1.maven.org/maven2/org/glassfish/javax.faces/2.2.0) to WEB-INF/lib solved the problem for me.Butane
Please note that the accepted answer is a wrong way of installing JSF on Tomcat. For the right way, see our JSF wiki page: stackoverflow.com/tags/jsf/infoHild
E
16

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.

Eglantine answered 17/8, 2013 at 1:39 Comment(3)
Apparently your Eclipse configuration is seriously messed up. I suggest to reinstall Eclipse for Java EE and not to change any of its settings unless you really really understand what exactly the setting is doing under the covers. Note that placing those libs in Tomcat's lib is not a solution, but a workaround. The real solution is to have those libs in webapp's /WEB-INF/lib. That that part doesn't work is a problem you'd still need to solve.Hild
@Hild thanks for the bad news, but for the time being this works for me i really wanted to learn some jsf :)Eglantine
I hope that you keep in mind that you shouldn't address this problem and all of its future consequences to JSF, but to the bad environment. You should have a good development and runtime environment to start with.Hild
A
1

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.

Aorist answered 16/1, 2014 at 12:1 Comment(0)
H
-1

This dependency contain required libraries and may fix your problem

'org.glassfish:javax.faces:2.3.0'
Haskell answered 21/4, 2017 at 8:43 Comment(0)
D
-2

Adding the following dependencies should solve the problem. I was creating a webapp with the JSF dependencies in the web.xml. So, had to add these in pom.xml to get the problem resolved.

    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.1.7</version>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.1.7</version>
    </dependency>

Use whichever version you require.

Decarburize answered 17/1, 2020 at 10:24 Comment(2)
Versions are 8 years old!!!!! Not the best answer due to thatHellraiser
OP is not using Maven.Hild

© 2022 - 2024 — McMap. All rights reserved.