java.lang.NoClassDefFoundError 使用 org.json 库
java.lang.NoClassDefFoundError using org.json library
我刚刚将 org.json
库导入到我的动态 Web 项目中。作为服务器,我使用 Tomcat
。当我尝试 运行 应用程序时,出现此错误:java.lang.NoClassDefFoundError: org/json/JSONObject
。这是我收到错误的代码:
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());
}
}
}
具体来说,这是我收到错误的行:
obj.put("salutation", lang.get(newPathInfo));
有什么我想念的吗?
谢谢!
我已将库复制到 WEB-INF/lib
文件夹,它正在运行
我刚刚将 org.json
库导入到我的动态 Web 项目中。作为服务器,我使用 Tomcat
。当我尝试 运行 应用程序时,出现此错误:java.lang.NoClassDefFoundError: org/json/JSONObject
。这是我收到错误的代码:
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());
}
}
}
具体来说,这是我收到错误的行:
obj.put("salutation", lang.get(newPathInfo));
有什么我想念的吗?
谢谢!
我已将库复制到 WEB-INF/lib
文件夹,它正在运行