0

I am trying to use the JSON-lib api in my code to convert a java object into a JSONObject.

I have added all of the dependencies with the versions specified on the link below to my j2ee web module dependencies

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

However, whenever I call the JSONObject.fromObject() method I get NoSuchMethodError.

I should also point out that the exact same code and dependencies work on my tomcat server but do not work on my websphere application server. Does anybody know what I may be doing wrong ?

Partial stack trace below:

 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)
skaffman
  • 398,947
  • 96
  • 818
  • 769
mh377
  • 1,656
  • 5
  • 22
  • 41

1 Answers1

0

Make sure you have the correct version of commons collections jar in your WEB-INF/lib and then set the "Classes loaded with application class loader first" option in your WebSphere admin console as shown here

Andrei Sfat
  • 8,440
  • 5
  • 49
  • 69
dims
  • 16
  • I solved the problem using by setting the application class loader to PARENT_LAST as specified here [http://www.coderanch.com/t/486721/JSF/java/JSF-websphere](http://www.coderanch.com/t/486721/JSF/java/JSF-websphere) This link is also useful for explaining websphere class loaders [http://www.technicalfacilitation.com/get.php?link=classloading](http://www.technicalfacilitation.com/get.php?link=classloading) – mh377 Jun 01 '11 at 08:30