Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse + Maven + JavaServer Faces -> ClassNotFoundException: StartupServletContextListener

Summary

When I try to run a JSF 2.0 application from within Eclipse (on Tomcat 7.0) I get the following exception:

Problem: SEVERE: Error configuring application listener of class org.apache.myfaces.webapp.StartupServletContextListener
java.lang.ClassNotFoundException: org.apache.myfaces.webapp.StartupServletContextListener

Details

I'm learning to develop JSF applications, using Eclipse. I started with a preconfigured Eclipse project: File->New->Dynamic Web Project->JavaServer Face v2.0 Project. Using this method Eclipse provides all dependencies. But I want to really learn how everything works. I want to remove the "magic", so I converted my project to a Maven project: Configure->Convert to Maven project.

I then created my pom.xml (based on http://myfaces.apache.org/build-tools/archetypes/myfaces-archetype-helloworld20/index.html), it contains the following:

<build>
    <finalName>jsf-facelets-tutorial</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <webXml>WebContent/WEB-INF/web.xml</webXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>javax.el</groupId>
        <artifactId>el-api</artifactId>
        <version>1.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.myfaces.core</groupId>
        <artifactId>myfaces-api</artifactId>
        <version>2.0.5</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.myfaces.core</groupId>
        <artifactId>myfaces-impl</artifactId>
        <version>2.0.5</version>
        <scope>runtime</scope>
    </dependency>
</dependencies>

But because I'm unfamiliar with JSF, and because this is an Eclipse "Dynamic Web Project", the project structure is new to me and I'm having trouble understanding which dependencies are coming from Maven and which are provided by the Eclipse "magic".

In Eclipse, my project structure is as follows:

ProjectName
  JAX-WS Web Services <-- CAN I REMOVE THIS???
  Deployment Descriptor
  Java Resources
    src/main
    Libraries
      Apache Tomcat v7.0
        el-api.jar
        jsp-api.jar
        [more...]
      JSF 2.0 (Apache MyFaces JSF Core-2.0 API 2.0.2) <-- I REMOVED THIS!!!
      EAR Libraries
      JRE System Library
      Maven Dependencies
        el-api-1.0.jar
        myfaces-api-2.0.5.jar
        myfaces-impl-2.0.5.jar
        [more...]
      Web App Libraries

Problem My (very basic) application (login page & welcome page) no longer runs. When I do the following:

(1) Right click on WebContent/login.xhtml
(2) Run as -> Run on Server
(3) Apache Tomcat v7.0 - JDK6 at localhost

I get the exception:

Problem: SEVERE: Error configuring application listener of class org.apache.myfaces.webapp.StartupServletContextListener
java.lang.ClassNotFoundException: org.apache.myfaces.webapp.StartupServletContextListener

I have the feeling that this is very easy to fix, but I'm too unfamiliar with these frameworks to work it out.

If there are any additional details I should provide (web.xml, faces-config-xml, login.xhtml), let me know and I'll add them.

Thanks!

EDIT

WEB-INF/lib is always empty. From my understanding, it's necessary to copy all dependencies into this folder, that will be required at runtime, and that are not provided by the Web Container. The reasons mine is empty are: (1) I don't know what I need in there (2) I don't know how to automate the process of putting .jar files in there

like image 701
Alex Averbuch Avatar asked Apr 02 '12 09:04

Alex Averbuch


2 Answers

Under your eclipse Project Properties, select Deployment Assembly from the navigation menu which defines "packaging structure for this Java EE Web Application project." Make sure you have all the project dependencies added here..

Or look into web server directory under workspace/.metadata/.plugins/org.eclipse.wst.server.core\tmp0 to check if the jars have been copied to catalina base.

like image 122
vinodn Avatar answered Sep 17 '22 02:09

vinodn


Sounds like you don't have all the jars in your target folder ready to deploy to tomcat

Try running a maven package in eclipse, right click on project, run as maven package

like image 43
Louis Q Avatar answered Sep 21 '22 02:09

Louis Q