Java - JSON对象和ListOrderedMap问题

时间:2011-05-31 15:06:27

标签: java websphere nosuchmethoderror apache-commons-collection

我试图在我的代码中使用JSON-lib api将java对象转换为JSONObject。

我已将以下链接中指定版本的所有依赖项添加到我的j2ee Web模块依赖项中

http://json-lib.sourceforge.net/

但是,每当我调用JSONObject.fromObject()方法时,我都会得到NoSuchMethodError。

我还应该指出完全相同的代码和依赖项在我的tomcat服务器上运行,但不能在我的websphere应用程序服务器上运行。有人知道我的错误吗?

下面的部分堆栈跟踪:

 E com.ibm.ws.webcontainer.webapp.WebApp logServletError SRVE0293E: [Servlet Error]-[SpringMVCServlet]: java.lang.NoSuchMethodError: org/apache/commons/collections/map/ListOrderedMap.<init>()V
    at net.sf.json.JSONObject.<init>(JSONObject.java:1450)
    at net.sf.json.util.CycleDetectionStrategy.<clinit>(CycleDetectionStrategy.java:37)
    at java.lang.J9VMInternals.initializeImpl(Native Method)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
    at net.sf.json.JsonConfig.<clinit>(JsonConfig.java:65)
    at java.lang.J9VMInternals.initializeImpl(Native Method)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
    at net.sf.json.JSONObject.fromObject(JSONObject.java:134)

1 个答案:

答案 0 :(得分:0)

确保在WEB-INF/lib中拥有正确版本的commons集合jar,然后在WebSphere管理控制台中设置"Classes loaded with application class loader first"选项,如图所示here