2011-06-15 55 views
2

我是JSF的新手。我使用Tomcat 7.0.14,並試圖運行SimpleHelloByEnteringName例子,但得到以下的啓動和運行時java.lang.NoClassDefFoundError:運行時的javax/el/ELResolver SimpleHelloByEnteringName JSF示例

啓動控制檯的信息錯誤:

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. 

這個問題是如何引起的?我該如何解決?

回答

7

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.

該警告是不相關的問題。 JSF已經爲你修復了它,但它告訴你,你應該自己修復它在faces-config.xml


java.lang.ClassNotFoundException: javax.el.ELResolver

然而,這是相當嚴重的。這可能有幾個原因:

  • 您實際上並未運行Tomcat 7.0,但是缺少此類的Tomcat 5.5。重新檢查它。

  • 你在web應用程序的WEB-INF/lib或Java的JRE/lib文件夾掉了一堆servletcontainer特定的庫如el-api.jarjsp-api.jar等不同servletcontainer化妝/版本(可能的Tomcat 5.5?)。可能要克服編譯問題。移動/複製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的Java EE學習資源worst。我強烈建議前往其他資源。

+3

+1 roseindia.net評論:) – Abhishek 2013-04-05 18:05:34

1

我執行在Eclipse動態Web項目時,也有類似的問題。

java.lang.NoClassDefFoundError: javax/el/ELResolver

這裏的問題是您在項目中使用的類在類路徑沒有定義。就我而言,我不得不添加

  1. EL-api.jar中
  2. 的jsp-api.jar中
  3. 的servlet-api.jar文件

到我的Tomcat的引導下,項目類路徑。

enter image description here

所以,在你的情況,檢查這些罐子3的是否存在於C:\ Tomcat的\ lib目錄。如果不存在,將它添加到類路徑中。

希望這可以解決您的問題。