编辑我的代码以与JNI一起使用后,我在JSP上得到了NoClassDefFoundError
。我似乎无法理解为什么将所有.java and .class
放在WEB-INF/classes/matrixcalculator
路径中。 .h, .c and .so
位于WEB-INF/classes/
文件夹旁边的matrixcalculator
中。这是代码错误日志:
java.lang.NoClassDefFoundError: Could not initialize class matrixcalculator.MatrixCalculator
org.apache.jsp.adminOnly_jsp._jspService(adminOnly_jsp.java:69)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:750)
org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:720)
org.apache.jsp.requestPermission_jsp._jspService(requestPermission_jsp.java:87)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
它在以前工作过,但是在刚添加本机函数,loadLibrary和其他文件之后,出现了此错误。我尝试将文件更改为
WEB-INF/classes/matrixcalculator
中的相同文件夹,但仍然无法摆脱错误。我相信这与将路径导出到MatrixCalculator.class的位置有关,但是我真的不明白该在哪里以及为什么。除非我将他的文件放在Tomcat的公用文件夹中,否则我可能是错的。我也直接调用JSP,而不使用Tomcat管理器我添加了
language = "java"
,并且在Java bean中出现错误:org.apache.jasper.JasperException: An exception occurred processing JSP page /adminOnly.jsp at line 8
5:-%>
6:
7:
8:
9:
10:
11:
这是静态块:
static {
System.loadLibrary("methodsViaC");
}
添加try / catch(异常e)后出现新错误:
java.lang.UnsatisfiedLinkError: no methodsViaC in java.library.path
java.lang.ClassLoader.loadLibrary(ClassLoader.java:1886)
java.lang.Runtime.loadLibrary0(Runtime.java:849)
java.lang.System.loadLibrary(System.java:1088)
matrixcalculator.MatrixCalculator.<clinit>(MatrixCalculator.java:77)
org.apache.jsp.adminOnly_jsp._jspService(adminOnly_jsp.java:69)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:750)
org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:720)
org.apache.jsp.requestPermission_jsp._jspService(requestPermission_jsp.java:87)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
但是,如果刷新页面,则会收到第一个错误。
最佳答案
此错误意味着无法初始化该类,但并不意味着找不到该类。因此,我的建议是在matrixcalculator.MatrixCalculator类中检查静态变量和静态初始化块。看起来未捕获的异常是在静态块中引发的。
关于java - Tomcat NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28563852/