title: java.lang.NoClassDefFoundError: org/json/JSONObject
body: <p>I am using Eclipse IDE and am writing a servlet. The servlet should accept values from an html file and return JSON response accordingly. </p>
  
  <p>My doPost() is:</p>
  
  <pre><code>protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
  
          try
          {
          res.setContentType("application/json");
          res.setHeader("Cache-Control", "nocache");
              res.setCharacterEncoding("utf-8");
  
          PrintWriter out = res.getWriter();
  
          JSONObject json = new JSONObject();
  
          String un=req.getParameter("uname");
          String pw=req.getParameter("password");
  
          if(un.equals("xxx") &amp;&amp; pw.equals("xxx"))            
              json.put("result", "success");
          else
              json.put("result", "fail");
  
          out.print(json.toString());
          }
          catch(Exception e){System.out.print( e.getMessage());}  
      }
  </code></pre>
  
  <p>When I run this servlet in Eclipse I get a file download dialog.</p>
  
  <p>When run outside Eclipse with Tomcat, I get error:</p>
  
  <pre><code>root cause
  
  java.lang.NoClassDefFoundError: org/json/JSONObject
      Server1.doPost(Server1.java:25)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
  
  root cause
  
  java.lang.ClassNotFoundException: org.json.JSONObject
      org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1713)
      org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1558)
      Server1.doPost(Server1.java:25)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
  </code></pre>
  
  <p>The line Server1.doPost(Server1.java:25) refers to </p>
  
  <pre><code>JSONObject json = new JSONObject();
  </code></pre>
  
  <p>I have added the org.json.jar to the build path as well as added it to deployment path in <code>Properties-&gt;Configure build path-&gt;Deployment assembly</code></p>