網頁

解決 Tomcat 之org.apache.jasper.JasperException: Unable to compile class for JSP問題

解決 Tomcat 之org.apache.jasper.JasperException: Unable to compile class for JSP問題

當你在Tomcat佈建專案時,常會發生一個錯誤,就是會將你的專案整個複製到Tomcat 的webapps目錄中
忘了WEB-INF目錄可能會存在於專案的目錄中,就會發生類似下列錯誤

HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

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

exception

org.apache.jasper.JasperException: Unable to compile class for JSP
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:597)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause

java.lang.NullPointerException
org.apache.catalina.loader.WebappClassLoader.findResourceInternal(WebappClassLoader.java:2672)
org.apache.catalina.loader.WebappClassLoader.findResource(WebappClassLoader.java:1088)
org.apache.catalina.loader.WebappClassLoader.getResourceAsStream(WebappClassLoader.java:1310)
org.apache.jasper.servlet.JasperLoader.getResourceAsStream(JasperLoader.java:144)
org.apache.jasper.compiler.JDTCompiler$1.findType(JDTCompiler.java:193)
org.apache.jasper.compiler.JDTCompiler$1.findType(JDTCompiler.java:178)
org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.createPackage(LookupEnvironment.java:639)
org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.buildTypeBindings(CompilationUnitScope.java:86)
org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.buildTypeBindings(LookupEnvironment.java:147)
org.eclipse.jdt.internal.compiler.Compiler.internalBeginToCompile(Compiler.java:590)
org.eclipse.jdt.internal.compiler.Compiler.beginToCompile(Compiler.java:357)
org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:371)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:429)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:589)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


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


--------------------------------------------------------------------------------

Apache Tomcat/6.0.26





解決的方式為將專案目錄中的WEB-INF目錄刪除即可解決這種無法建立class的jar衝突