1

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!

DamianFox
  • 902
  • 3
  • 20
  • 45
  • 1
    Sounds like you're missing "including the library in your classpath" but you haven't told us what you're doing in terms of that... – Jon Skeet Nov 02 '15 at 14:50
  • 1
    Your'e missing the org.json jar as a dependency for your project. You need to add it to your classpath. – Avihoo Mamka Nov 02 '15 at 14:52
  • Is your project being built with maven? It seems from your answer using WEB-INF/lib that it might be... in this case the solution you found is masking some other problem you have with your project set up. – James Dunn Nov 02 '15 at 15:12

1 Answers1

1

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

DamianFox
  • 902
  • 3
  • 20
  • 45