关于打包自定义标签,并导入项目使用时,出现java.lang.NoClassDefFoundError: JspException异常,解决方法和注意事项!

坑死我了啊!!!!事先不知道,还以为哪里出了bug,百度这个异常可能出现的原因,都没解决,最后百度关键字“打包自定义标签库 出现异常”出现的第一个链接才解决的,Stack Overflow上也有关于这个答案,链接:javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax/servlet/ServletInputStream


具体方法:

1.新建一个普通的java项目,将自己写的所有的标签处理器类连同包一起复制进去。

2.在项目下新建一个META-INF文件夹放上tld文件!


3.最重要的是!!!一定要在项目中导入servlet-api.jar和jsp-api.jar!!!在项目中新建一个lib文件夹,把这个jar导进去,再Build Path,具体文件结构如下图所示(exa是我的项目名):

关于打包自定义标签,并导入项目使用时,出现java.lang.NoClassDefFoundError: JspException异常,解决方法和注意事项!_第1张图片
然后再打包,导入项目运行时就不会抛异常了。
关于 servlet-api.jar和jsp-api.jar可以在tomcat的lib目录下找到。

附上异常的完整信息:

HTTP Status 500 - java.lang.NoClassDefFoundError: JspException

type Exception report

message java.lang.NoClassDefFoundError: JspException

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

exception

javax.servlet.ServletException: java.lang.NoClassDefFoundError: JspException
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:348)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:731)

root cause

java.lang.NoClassDefFoundError: JspException
	java.lang.Class.getDeclaredMethods0(Native Method)
	java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
	java.lang.Class.getDeclaredMethods(Class.java:1791)
	java.beans.Introspector$1.run(Introspector.java:1272)
	java.security.AccessController.doPrivileged(Native Method)
	java.beans.Introspector.getPublicDeclaredMethods(Introspector.java:1270)
	java.beans.Introspector.getTargetMethodInfo(Introspector.java:1136)
	java.beans.Introspector.getBeanInfo(Introspector.java:387)
	java.beans.Introspector.getBeanInfo(Introspector.java:159)
	org.apache.jasper.compiler.Generator$TagHandlerInfo.<init>(Generator.java:3983)
	org.apache.jasper.compiler.Generator$GenerateVisitor.getTagHandlerInfo(Generator.java:2226)
	org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1654)
	org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1553)
	org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2392)
	org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2444)
	org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2450)
	org.apache.jasper.compiler.Node$Root.accept(Node.java:474)
	org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2392)
	org.apache.jasper.compiler.Generator.generate(Generator.java:3529)
	org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:251)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:374)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:354)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:341)
	org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:662)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:364)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:731)

root cause

java.lang.ClassNotFoundException: JspException
	org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1858)
	org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1709)
	java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
	java.lang.Class.getDeclaredMethods0(Native Method)
	java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
	java.lang.Class.getDeclaredMethods(Class.java:1791)
	java.beans.Introspector$1.run(Introspector.java:1272)
	java.security.AccessController.doPrivileged(Native Method)
	java.beans.Introspector.getPublicDeclaredMethods(Introspector.java:1270)
	java.beans.Introspector.getTargetMethodInfo(Introspector.java:1136)
	java.beans.Introspector.getBeanInfo(Introspector.java:387)
	java.beans.Introspector.getBeanInfo(Introspector.java:159)
	org.apache.jasper.compiler.Generator$TagHandlerInfo.<init>(Generator.java:3983)
	org.apache.jasper.compiler.Generator$GenerateVisitor.getTagHandlerInfo(Generator.java:2226)
	org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1654)
	org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1553)
	org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2392)
	org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2444)
	org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2450)
	org.apache.jasper.compiler.Node$Root.accept(Node.java:474)
	org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2392)
	org.apache.jasper.compiler.Generator.generate(Generator.java:3529)
	org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:251)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:374)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:354)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:341)
	org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:662)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:364)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:731)

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


你可能感兴趣的:(tomcat,jsp,打包自定义标签)