我创建了一个小型EXTJS应用程序,它通过servlet发送请求。 servlet看起来使用JSON进行响应,但是我得到了JSON数组的类找不到异常:
日志中的异常:
org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [ItemMaintenance] in context with path
[/EXTTestServlet] threw exception [Servlet execution threw an exception] with root cause:
java.lang.NoClassDefFoundError: Could not initialize class net.sf.json.JSONArray
at com.as400samplecode.ItemMaintenance.doGet(ItemMaintenance.java:44)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2476)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2465)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
我知道每个人都会说"你需要把JSON JAR文件放在WEB-INF"但它已经存在,我也尝试添加JSON所需的依赖项。我也尝试了不同的版本,没有成功。
我也遵循了本教程:http://javaeesupportpatterns.blogspot.co.uk/2012/08/javalangnoclassdeffounderror-parent.html来尝试理解如何在Java EE中发现类未找到异常以及可能的解决方案。
任何人都可以指出我正确的方向,在哪里看下一个或建议为什么会发生这种情况?
由于
答案 0 :(得分:1)
As an update I've managed to fix the problem. It stemmed from Apache Commons Collections API. A package located in this library reads: org.apache.commons.collections4 where the package generated from within the JSON library is pointing towards org.apache.commons.collections
The added 4 at the end of the package was playing havoc, so watch that it doesn't catch you out.
答案 1 :(得分:0)
在pom.xml中,您必须提及所有必要的依赖项。只有这样,所需的jar文件才会反映在maven依赖项索引中,并且也会被映射。.