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!

3
  • 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... Commented Nov 2, 2015 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. Commented Nov 2, 2015 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. Commented Nov 2, 2015 at 15:12

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.