项目中导入了 json-lib 包,但是在运行如下代码的时候还是出现了如下错误,究其原因是因为缺包,缺了如下5个包:
commons-lang-2.6 (注:导入最新的 3.1 版本会继续报如下错误)
Json Lib 下载:json-lib-2.4
import net.sf.json.JSONObject;
public class TestJson {
public static void main(String[] args){
Map<String, String> map = new HashMap<String, String>();
map.put("key", "value");
map.put("name", "abc");
JSONObject json = JSONObject.fromObject(map);
System.out.println(json);
}
}
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException
......
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRuntimeException