Search code examples
javajsontomcatnoclassdeffounderror

java.lang.NoClassDefFoundError using org.json library


I've just imported the org.json library to my Dynamic Web Project. As a server, I'm using Tomcat. When I try to run the application I get this error: java.lang.NoClassDefFoundError: org/json/JSONObject. This is the code where I'm getting the error:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String pathInfo = request.getPathInfo();

        if(pathInfo != null){
            String newPathInfo = pathInfo.substring(1);
            System.out.println("--> " + pathInfo);
            System.out.println("--> " + newPathInfo);

            System.out.println("parameter --> " + request.getParameter("format"));
            String format = request.getParameter("format");

            if(format != null){
                if(format.equals("json")){                      
                    System.out.println("Preparing JSON reply...");
                    response.setContentType("text/json");

                    JSONObject obj = new JSONObject();
                    obj.put("salutation", lang.get(newPathInfo));

                    response.getWriter().write(obj.toString());
                    System.out.println("--> "+obj.toString());
                }   
            }
        }

Specifically, this is the line where I'm getting the error:

obj.put("salutation", lang.get(newPathInfo));

Is there something I am missing?
Thanks!


Solution

  • I've copied the library to the WEB-INF/lib folder and it is working