Eclipse + Maven + JavaServer Faces -> ClassNotFoundException: StartupServletContextListener



摘要

当我尝试在Eclipse中(在Tomcat7.0上)运行JSF 2.0应用程序时,我会得到以下异常:

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

详细信息

我正在学习使用Eclipse开发JSF应用程序。我从一个预配置的Eclipse项目开始:File->New->DynamicWebProject->JavaServerFacev2.0项目。使用这种方法,Eclipse提供了所有依赖项。但我想真正了解一切是如何运作的。我想去掉"魔术",所以我把我的项目转换成了一个Maven项目:配置->转换成Maven项目。

然后我创建了pom.xml(基于http://myfaces.apache.org/build-tools/archetypes/myfaces-archetype-helloworld20/index.html),它包含以下内容:

<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>

但由于我不熟悉JSF,而且这是一个Eclipse"动态Web项目",项目结构对我来说是新的,我很难理解哪些依赖项来自Maven,哪些依赖项由Eclipse"魔力"提供。

在Eclipse中,我的项目结构如下:

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

问题我的(非常基本的)应用程序(登录页面和欢迎页面)不再运行。当我执行以下操作时:

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

我得到了一个例外:

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

我觉得这很容易解决,但我对这些框架太陌生了,无法解决。

如果我应该提供任何其他详细信息(web.xml、faces-config.xml、login.xhtml),请告诉我,我会添加它们。

谢谢!

编辑

WEB-INF/lib始终为空。据我所知,有必要将所有依赖项复制到此文件夹中,这是运行时所必需的,而Web容器没有提供。我的文件为空的原因是:(1)我不知道我需要什么(2)我不了解如何自动将.jar文件放入

在eclipse项目属性下,从导航菜单中选择Deployment Assembly,该菜单定义了"此Java EE Web应用程序项目的打包结构"。请确保在此处添加了所有项目依赖项。。

或者查看workspace/.metadata/.plugins/org.eclipse.wst.server.core\tmp0下的web服务器目录,检查jar是否已复制到catalina库。

听起来目标文件夹中的所有jar都没有准备好部署到tomcat

尝试在eclipse中运行一个maven包,右键单击项目,作为maven包运行

最新更新