java.lang.NoClassDefFoundError:运行 SimpleHelloByEnteringName JSF 示例时的 javax/el/ELResolver
Posted
技术标签:
【中文标题】java.lang.NoClassDefFoundError:运行 SimpleHelloByEnteringName JSF 示例时的 javax/el/ELResolver【英文标题】:java.lang.NoClassDefFoundError: javax/el/ELResolver when running SimpleHelloByEnteringName JSF example 【发布时间】:2011-09-15 15:37:05 【问题描述】:我是 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.
这个问题是怎么引起的,我该如何解决?
【问题讨论】:
【参考方案1】:在 Eclipse 中执行动态 Web 项目时,我遇到了类似的问题。
java.lang.NoClassDefFoundError: javax/el/ELResolver
这里的问题是您在项目中使用的类未在 类路径 中定义。就我而言,我必须添加
-
el-api.jar
jsp-api.jar
servlet-api.jar
在 Bootstrap 条目下进入我的 Tomcat 的类路径。
因此,在您的情况下,请检查这 3 个 jar 是否存在于 C:\Tomcat\lib 目录中。如果不存在,请将其添加到类路径中。
希望这能解决您的问题。
【讨论】:
【参考方案2】:警告:JSF1058:to-view-id 引用的资源“result.jsp”,用于从“/pages/inputname.jsp”导航,不以“/”开头。这将为您添加,但应该更正。
警告与问题无关。 JSF 已经为您修复了它,但它告诉您应该在faces-config.xml
中自己修复它。
java.lang.ClassNotFoundException: javax.el.ELResolver
然而,这非常严重。这可能有几个原因:
您实际上根本没有运行 Tomcat 7.0,而是缺少此类的 Tomcat 5.5。仔细检查一下。
1234563文件夹。可能是为了克服编译问题。移动/复制特定于 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>
更新:哦,等等……我在“SimpleHelloByEnteringName”上搜索了一下,发现这实际上是一个 Roseindia.net (shudder) 示例,如下所示: Downloading and Installing "SimpleHelloByEnteringName" JSF Example。我想强调一下,这个站点是互联网上的worst Java EE 学习资源。我强烈建议前往其他资源。
Coreservlets.com JSF 2.0 tutorial Java EE 6 tutorial - JSF Mkyong.com JSF 2.0 tutorials My JSF 2.0 tutorial with Eclipse and Glassfish【讨论】:
以上是关于java.lang.NoClassDefFoundError:运行 SimpleHelloByEnteringName JSF 示例时的 javax/el/ELResolver的主要内容,如果未能解决你的问题,请参考以下文章