Issue
I have created a small EXTJS app that looks to send a request through a servlet. The servlet looks to respond using JSON but I am getting a class not found exception for the JSON array:
Exception in log:
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)
I know everyone is going to say "You need to put the JSON JAR file in WEB-INF" but it is already there and I have also tried to add the dependencies required for JSON. I have tried different version too, with no success.
I also followed this tutorial: http://javaeesupportpatterns.blogspot.co.uk/2012/08/javalangnoclassdeffounderror-parent.html to try and make sense of how class not found exceptions can happen in Java EE and what possible solutions may be available.
Can anyone point me in the right direction with where to look next or suggest why this may be happening ?
Thanks
Solution
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.
Answered By - Nathan