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
posted
0
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.
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
posted
0
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.
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.
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.