Summary
当我尝试从 Eclipse 中(在 Tomcat 7.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
Details
我正在学习使用 Eclipse 开发 JSF 应用程序。
我从预配置的 Eclipse 项目开始:文件 -> 新建 -> 动态 Web 项目 -> JavaServer Face v2.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
Problem我的(非常基本的)应用程序(登录页面和欢迎页面)不再运行。
当我执行以下操作时:
(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),请告诉我,我将添加它们。
Thanks!
EDIT
WEB-INF/lib 始终为空。根据我的理解,有必要将所有依赖项复制到此文件夹中,这些依赖项在运行时需要,并且 Web 容器不提供。我的空的原因是:(1)我不知道我需要什么(2)我不知道如何自动化将 .jar 文件放入其中的过程