0

I have been using JSONObject from org.json in my Servlet class. However, when I try to run the app I get the following error:

Caused by: java.lang.NoClassDefFoundError: Lorg/json/JSONObject;
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
at java.lang.Class.getDeclaredFields(Class.java:1916)
at org.apache.catalina.util.Introspection.getDeclaredFields(Introspection.java:110)
at org.apache.catalina.startup.WebAnnotationSet.loadFieldsAnnotation(WebAnnotationSet.java:262)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:136)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:66)
at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:328)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:778)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:299)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:94)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5087)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 42 more
Caused by: java.lang.ClassNotFoundException: org.json.JSONObject
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1285)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
... 55 more

I have no idea why this is happening only in the Servlet class. I verified running a standalone program using JSONObject in the same module and it ran fine. This issue is happening only when I use the JSONObject in the doPost method of my Servlet. I wasted lot of time on this and wanted some help badly. I'm running the app in IntelliJ.

12
  • What version of JDK are you using? Commented Nov 18, 2016 at 18:54
  • Check out this answer: stackoverflow.com/questions/18346609/… Commented Nov 18, 2016 at 18:55
  • I am using JDK 1.8 Commented Nov 18, 2016 at 18:56
  • Well its running fine in a standalone program in the same module. The issue happens only in the Servlet code. I have added the maven dependency, made sure the libraries exist. Commented Nov 18, 2016 at 18:58
  • Catalina might be running in jdk6. Can you double check catalina config file? Commented Nov 18, 2016 at 19:00

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.