my dog learned polymorphism*
The moose likes Struts and the fly likes Struts2 + JSON : Getting Class Not Found Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2 + JSON : Getting Class Not Found Error" Watch "Struts2 + JSON : Getting Class Not Found Error" New topic
Author

Struts2 + JSON : Getting Class Not Found Error

Girish Kumar Prabhakar
Ranch Hand

Joined: Dec 09, 2008
Posts: 34
Hi All,

I am integrating Struts2 and JSON. For this, i am using Struts2 inbuilt support for JSON. But i am getting the following error.
java.lang.NoClassDefFoundError: org/apache/commons/lang/xwork/StringUtils

I have searched on net, but could find this jar, instead commons-lang.jar have org/apache/commons/lang/StringUtils class and no xwork package.

Here is my struts.xml and jsp code.

struts.xml
<package name="default" namespace="/" extends="struts-default">
<result-types>
<result-type name="json" class="org.apache.struts2.json.JSONResult" />
</result-types>

<action name="jsonAction" class="com.AutoComplete">
<result name="SUCCESS" type="json"><param name="root">myList</param></result>
</action>
</package>

jsp code
<s:url id="myList" value="jsonAction"/>
<sx:autocompleter label="Enter" href="%{myList}" name="city" autoComplete="true"></sx:autocompleter>

I am using spring2-core-2.1.6.jar and xwork-2.1.2.jar.

Thanks in advance.
Girish
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

spring2-core-2.1.6.jar?

That aside: is there more to the stack trace than that?
Girish Kumar Prabhakar
Ranch Hand

Joined: Dec 09, 2008
Posts: 34
Hi David,

Thanks for your reply.
This is the full stacktrace which i am getting.





Or, is there any better way to implement json?

Thanks
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please list the actual jars you're deploying.
Girish Kumar Prabhakar
Ranch Hand

Joined: Dec 09, 2008
Posts: 34
Hi David,

These are the jars i am using :

struts2-core-2.1.6.jar
xstream-1.2.2.jar
xwork-2.1.2.jar
freemarker-2.3.8.jar
ognl-2.6.9.jar
dom4j-1.6.1.jar
commons-collections-3.1.jar
commons-dbcp-1.2.2.jar
commons-logging-1.0.4.jar
struts2-spring-plugin-2.0.11.2.jar
tiles-api-2.1.2.jar
tiles-core-2.1.2.jar
tiles-jsp-2.1.2.jar
struts2-tiles-plugin-2.0.12.jar
spring.jar


Is there any other information you require.

Thanks.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Where is the JSON plugin jar?

And *please* only use plugins from the same version of Struts you're using? It isn't reasonable to mix-and-match like that.
Girish Kumar Prabhakar
Ranch Hand

Joined: Dec 09, 2008
Posts: 34
I am using struts2-json-plugin-2.1.8.1.jar for JSON plugin jar.

I am new to Struts2, so can you please explain your last line, or point out which plugins i am mixing and matching or using wrong versions.

Thanks David.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

If I asked you to list all the jars you're deploying, why isn't that one in the list?!

In any case: see all those Struts 2 jars? See how the versions aren't the same? That *will not work*.
Girish Kumar Prabhakar
Ranch Hand

Joined: Dec 09, 2008
Posts: 34
Is the version of JSON plugin correct or there is some other version.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

YOU CANNOT MIX PLUGIN VERSIONS AS YOU ARE DOING NOW.

1) Do you see the Struts 2 jars you've listed?

I'll list them again for you:

struts2-core-2.1.6.jar
struts2-spring-plugin-2.0.11.2.jar
struts2-tiles-plugin-2.0.12.jar
struts2-json-plugin-2.1.8.1.jar

2) Do you see how the version numbers are different?

That won't work.

Use the version of the plugin that matches the version of Struts 2 you're using.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts2 + JSON : Getting Class Not Found Error
 
Similar Threads
Struts2 JSON problem
struts2 + Json and JQuery.
Struts2-json plugin not serializing action class to json
Struts2 Validation
struts2 + interceptor