aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes JSON XMLSerializer class not found error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "JSON XMLSerializer class not found error" Watch "JSON XMLSerializer class not found error" New topic
Author

JSON XMLSerializer class not found error

Supraja Jayakumar
Greenhorn

Joined: Jul 12, 2011
Posts: 7
Hi

I was trying out JSON and included json.lib in my classpath.
I was trying out an example to convert xml to JSON.

But i keep getting classnotfound error with xmlserializer though
the class is there in the json lib.

It tries to find some other xmlserializer elsewhere. I deleted that file totally but
still it complains.

What is this problem. Its kind of weird.

Thanks
Supraja J
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18675
    
    8

Any number of things could be wrong. Post the stack trace and the code which threw the exception.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
Also - are you trying to compile with an IDE or directly from the command line?

Bill
Supraja Jayakumar
Greenhorn

Joined: Jul 12, 2011
Posts: 7
Paul Clapham wrote:Any number of things could be wrong. Post the stack trace and the code which threw the exception.


OK. Here it is.

Exception in thread "main" java.lang.NoClassDefFoundError: nu/xom/Serializer
at jsontoxml.ConvertXMLToJSON.main(ConvertXMLToJSON.java:20)
Caused by: java.lang.ClassNotFoundException: nu.xom.Serializer
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more

Thanks for your help.
Supraja Jayakumar
Greenhorn

Joined: Jul 12, 2011
Posts: 7
William Brogden wrote:Also - are you trying to compile with an IDE or directly from the command line?

Bill


No. I am using eclipse. I put the json lib in the classpath. Then put the sample xml file in the class path too since
I did:


But this led to a null pointer exception since the IOUtils.toString(is) dint work out. IOUtils belongs to org.apache

Then I read it as a normal file using BufferedReader. The file was read but I got classnotfound exception later.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18675
    
    8

What's this "json.lib" thing? Is it a jar file? If so, did you examine it to see if that XOM class was in it? (I would expect XOM to be a dependency, instead of being combined with JSON, but then the documentation should have said that.)
Supraja Jayakumar
Greenhorn

Joined: Jul 12, 2011
Posts: 7
Paul Clapham wrote:What's this "json.lib" thing? Is it a jar file? If so, did you examine it to see if that XOM class was in it? (I would expect XOM to be a dependency, instead of being combined with JSON, but then the documentation should have said that.)


Hi Paul

Yes. JSON is a jar that helps converting xml files into json (A slightly light weight and more readable format)json
And no, XOM does'nt seem to be part of that. There was a dependency file given.
I think it maybe that the file is not being identified or something.

So in that case, let me tell you what I did. I created a new File (add->new->file) in eclipse and copied the dependency to this and put it in the class path.
It was something like this:


I have'nt added a dependency before so I did right click on Project in eclipse->import->import archive file.
Is this how it is done. Probably this is the problem.

Thanks
Supraja J
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18675
    
    8

Yes, I know what JSON is. And yes, I know what XOM is. However your question appears to be how to configure Eclipse so that your classpath is correct. In other words it doesn't have much to do with Java programming. So let me move the question to the IDEs forum.
Joonas Reynders
Greenhorn

Joined: Mar 01, 2010
Posts: 2
To fix add this to your maven dependencies:


Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5837
    
    7

When you created your project in Eclipse, did you create it as a Maven project? If you did, then the m2eclipse plugin should keep the Eclipse list of JARs in sync with the dependencies (you might have to right-click the project and choose Maven | Update Project or Update Dependencies). If you did not create a Maven project, then you will have to manually add those JARs to your Java Build Path for your project.


JBoss In Action
 
Consider Paul's rocket mass heater.
 
subject: JSON XMLSerializer class not found error