java.lang.NoClassDefFoundError:运行SimpleHelloByEnteringName时的javax / el / ELResolver JSF示例

时间:2011-06-15 15:20:31

标签: jsf tomcat jsf-2

我是JSF的新手。我正在使用Tomcat 7.0.14并尝试运行SimpleHelloByEnteringName示例,但在启动时和运行时遇到以下错误

启动控制台消息:

INFO: Deploying web application directory SimpleHelloByEnteringName
Jun 15, 2011 7:35:42 AM com.sun.faces.config.ConfigureListener contextInitialized
INFO: Initializing Mojarra 2.0.3 (FCS b03) for context '/SimpleHelloByEnteringName'
Jun 15, 2011 7:35:43 AM com.sun.faces.spi.InjectionProviderFactory createInstance
INFO: JSF1048: PostConstruct/PreDestroy annotations present.  ManagedBeans methods marked with these annotations will have said annotations processed.

**Jun 15, 2011 7:35:44 AM com.sun.faces.config.processor.NavigationConfigProcessor addNavigationCasesForRule
WARNING: JSF1058: The resource referred to by to-view-id, 'result.jsp', for navigation from '/pages/inputname.jsp', does not start with '/'.  This will be added for you, but it should be corrected.**

Jun 15, 2011 7:35:44 AM com.sun.faces.config.ConfigureListener$WebConfigResourceMonitor$Monitor <init>
INFO: Monitoring jndi:/localhost/SimpleHelloByEnteringName/WEB-INF/faces-config.xml for modifications
Jun 15, 2011 7:35:44 AM org.apache.coyote.AbstractProtocolHandler start
INFO: Starting ProtocolHandler ["http-apr-8081"]
Jun 15, 2011 7:35:44 AM org.apache.coyote.AbstractProtocolHandler start
INFO: Starting ProtocolHandler ["ajp-apr-8009"]
Jun 15, 2011 7:35:44 AM org.apache.catalina.startup.Catalina start
尝试运行http://localhost:8081/SimpleHelloByEnteringName/

时出现

和运行时错误

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax/el/ELResolver
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:342)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

root cause

java.lang.NoClassDefFoundError: javax/el/ELResolver
    java.lang.ClassLoader.defineClass1(Native Method)
    java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    java.security.AccessController.doPrivileged(Native Method)
    java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    sun.misc.Launcher$ExtClassLoader.findClass(Launcher.java:229)
    java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    java.lang.ClassLoader.loadClass(ClassLoader.java:295)
    sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    java.lang.ClassLoader.loadClass(ClassLoader.java:295)
    java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    org.apache.jasper.runtime.JspFactoryImpl.getJspApplicationContext(JspFactoryImpl.java:220)
    org.apache.jsp.index_jsp._jspInit(index_jsp.java:23)
    org.apache.jasper.runtime.HttpJspBase.init(HttpJspBase.java:49)
    org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:171)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:356)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

root cause

java.lang.ClassNotFoundException: javax.el.ELResolver
    java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    java.security.AccessController.doPrivileged(Native Method)
    java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    sun.misc.Launcher$ExtClassLoader.findClass(Launcher.java:229)
    java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    java.lang.ClassLoader.defineClass1(Native Method)
    java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    java.security.AccessController.doPrivileged(Native Method)
    java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    sun.misc.Launcher$ExtClassLoader.findClass(Launcher.java:229)
    java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    java.lang.ClassLoader.loadClass(ClassLoader.java:295)
    sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    java.lang.ClassLoader.loadClass(ClassLoader.java:295)
    java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    org.apache.jasper.runtime.JspFactoryImpl.getJspApplicationContext(JspFactoryImpl.java:220)
    org.apache.jsp.index_jsp._jspInit(index_jsp.java:23)
    org.apache.jasper.runtime.HttpJspBase.init(HttpJspBase.java:49)
    org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:171)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:356)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.14 logs.

这个问题是如何引起的?如何解决?

2 个答案:

答案 0 :(得分:7)

  

警告:JSF1058:to-view-id引用的资源'result.jsp'用于从'/pages/inputname.jsp'导航,不以'/'开头。这将为您添加,但应该更正。

警告与问题无关。 JSF已经为您修复了它,但它告诉您应该自己在faces-config.xml中修复它。


  

java.lang.ClassNotFoundException:javax.el.E​​LResolver

然而,这是非常严重的。这可能有几个原因:

  • 你实际上根本没有运行Tomcat 7.0,而是缺少这个类的Tomcat 5.5。双击它。

  • 你已经在webapp的el-api.jar中删除了一堆servletcontainer特定库,例如jsp-api.jarWEB-INF/lib等不同的servletcontainer make / version(可能是Tomcat 5.5?)或者在Java的JRE/lib文件夹中。可能是为了克服编译问题。移动/复制servletcontainer特定的JAR是错误的解决方案。撤消它并将它们全部删除。

  • 您的web.xml未被声明符合Servlet 2.5规范。既然你提到要使用Tomcat 7.0,这是一个Servlet 3.0容器,你应该声明web.xml符合Servlet 3.0:

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app 
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        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">
    
        <!-- Your config here -->
    </web-app>
    

更新:哦等等...我在google上搜索了“SimpleHelloByEnteringName”,我发现这实际上是一个Roseindia.net( shudder )示例,如下所示: Downloading and Installing "SimpleHelloByEnteringName" JSF Example。我想强调一下,这个站点是interwebs上的worst Java EE学习资源。我强烈建议您前往其他资源。

答案 1 :(得分:2)

在Eclipse中执行Dynamic Web项目时遇到了类似的问题。

  

java.lang.NoClassDefFoundError:javax / el / ELResolver

问题是您在项目中使用的类未在类路径中定义。在我的情况下,我不得不添加

  1. EL-api.jar文件
  2. 的jsp-api.jar文件
  3. servlet的api.jar文件
  4. 进入我的Tomcat在Bootstrap条目下的类路径。

    enter image description here

    所以,在你的情况下,检查这三个jar是否存在于C:\ Tomcat \ lib目录中。如果不存在,则将其添加到类路径中。

    希望这能解决你的问题。