Eclipse + Maven + JavaServer Faces - > ClassNotFoundException:StartupServletContextListener [英] Eclipse + Maven + JavaServer Faces -> ClassNotFoundException: StartupServletContextListener

查看:279
本文介绍了Eclipse + Maven + JavaServer Faces - > ClassNotFoundException:StartupServletContextListener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

总结



当我尝试从Eclipse(在Tomcat 7.0中)运行JSF 2.0应用程序时,我得到以下异常: / p>

 问题:SEVERE:配置org.apache.myfaces.webapp.StartupServletContextListener类的应用程序侦听器错误
java.lang时出错。 ClassNotFoundException:org.apache.myfaces.webapp.StartupServletContextListener

详细信息 p>

我正在学习使用Eclipse开发JSF应用程序。
我从一个预配置的Eclipse项目开始:File-> New-> Dynamic Web Project-> JavaServer Face v2.0 Project。
使用这个方法Eclipse提供了所有的依赖关系。但是我想真正了解一切如何运作。我想删除魔法,所以我将我的项目转换为Maven项目:配置 - >转换为Maven项目。



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

  ;建立> 
< 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>
<依赖关系>
<依赖关系>
< groupId> javax.el< / groupId>
< artifactId> el-api< / artifactId>
< version> 1.0< / version>
< scope>已提供< / scope>
< / dependency>
<依赖关系>
< groupId> junit< / groupId>
< artifactId> junit< / artifactId>
< version> 4.0< / version>
< scope> test< / scope>
< / dependency>
<依赖关系>
< groupId> org.apache.myfaces.core< / groupId>
< artifactId> myfaces-api< / artifactId>
< version> 2.0.5< / version>
< scope> compile< / scope>
< / dependency>
<依赖关系>
< groupId> org.apache.myfaces.core< / groupId>
< artifactId> myfaces-impl< / artifactId>
< version> 2.0.5< / version>
< scope>运行时< / scope>
< / dependency>
< / dependencies>

但是,由于我不熟悉JSF,因为这是一个Eclipse动态Web项目项目结构对我来说是新的,我无法理解来自Maven的依赖关系,而且由Eclipsemagic提供。



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

  ProjectName 
JAX-WS Web服务& - - 我可以删除这个? ?
部署描述符
Java资源
src / main

Apache Tomcat v7.0
el-api.jar
jsp-api。 jar
[更多...]
JSF 2.0(Apache MyFaces JSF Core-2.0 API 2.0.2) - - 我删除了!
EAR库
JRE系统库
Maven依赖关系
el-api-1.0.jar
myfaces-api-2.0.5.jar
myfaces-impl -2.0.5.jar
[更多...]
Web应用程序库

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

 (1)右键单击WebContent / login.xhtml 
2)运行为 - >运行在服务器
(3)Apache Tomcat v7.0 - JDK6在本地主机

我得到例外:

 问题:SEVERE:配置类org.apache.myfaces.webapp.StartupServletContextListener的应用程序侦听器错误
java.lang.ClassNotFoundException:org.apache.myfaces.webapp.StartupServletContextListener

我觉得这个很容易修复,但是我对这些框架太陌生,可以使用它。



如果有任何其他细节我应该提供(web.xml,面孔-config-xml,login.xhtml),让我知道,我会添加他们。



谢谢!



编辑



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

解决方案

在您的Eclipse项目属性下,从导航菜单中选择部署组件,该菜单定义了此Java EE Web应用程序项目的打包结构。确保你在这里添加了所有的项目依赖项。



或查看工作区/ .metadata / .plugins / org.eclipse.wst.server下的Web服务器目录。核心\tmp0,以检查罐是否已被复制到catalina base。


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

解决方案

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.

这篇关于Eclipse + Maven + JavaServer Faces - &gt; ClassNotFoundException:StartupServletContextListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆