3

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

Nathan
  • 266
  • 4
  • 16
  • Did you check the WAR to make sure the JAR in question is actually there? Sorry gotta ask you this. – Tim Biegeleisen Jul 08 '15 at 10:42
  • Yes its in there, I don't blame you for checking though haha – Nathan Jul 08 '15 at 10:43
  • Can you show us the portions of your POM dependencies for the JSONArray class? – Tim Biegeleisen Jul 08 '15 at 10:44
  • Look at: http://stackoverflow.com/questions/7325579/java-lang-noclassdeffounderror-could-not-initialize-class-xxx – Vartlok Jul 08 '15 at 10:52
  • Hmm this may be the issue then, I don't have a POM file associated with it. What I referred to in the question RE: dependencies, I was talking about including them with the classpath following: http://json-lib.sourceforge.net/ – Nathan Jul 08 '15 at 10:55

2 Answers2

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.

Nathan
  • 266
  • 4
  • 16
0

In pom.xml you have to mention all the necessary dependencies..only then the needed jar files will be reflected in the maven dependecies index and also will be mapped..