Error Message

R

Raghu

Hi All,

I am working on Java Binding using Castor. I got the following runtime
error while i ran the code.

java.lang.NoClassDefFoundError: org/apache/xml/serialize/XMLSerializer
at org.exolab.castor.xml.Marshaller.initialize(Marshaller.java:393)
at org.exolab.castor.xml.Marshaller.<init>(Marshaller.java:354)
at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:662)
at XMLJavaBinding.TestBinding.main(TestBinding.java:31)
Exception in thread "main"


The code is

package XMLJavaBinding;

/**
* @author rsanka
*
* To change the template for this generated type comment go to
* Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and
Comments
*/

import java.io.*;
import org.exolab.castor.xml.*;

public class TestBinding {

public static void main(String[] args) {
FlightBean bean = new FlightBean ();
bean.setCarrier ("Lufthansa");
bean.setNumber (426);
bean.setDepartureTime ("6:30a");
bean.setArrivalTime ("8:45a");

try {
File file = new File ("test.xml");
Writer writer = new FileWriter (file);
Marshaller.marshal (bean, writer);

Reader reader = new FileReader (file);
FlightBean read = (FlightBean) Unmarshaller.unmarshal
(FlightBean.class, reader);
System.out.println ("Flight " + read.getCarrier () + read.getNumber
() + " departing at " +
read.getDepartureTime () + " and arriving at " +
read.getArrivalTime ());
} catch (IOException ex) {
ex.printStackTrace (System.err);
} catch (MarshalException ex) {
ex.printStackTrace (System.err);
} catch (ValidationException ex) {
ex.printStackTrace (System.err);
}
}
}

Kindly provide me with the work around..

Thanks,
Raghu
 
C

Christophe Vanfleteren

Raghu said:
Hi All,

I am working on Java Binding using Castor. I got the following runtime
error while i ran the code.

java.lang.NoClassDefFoundError: org/apache/xml/serialize/XMLSerializer
at org.exolab.castor.xml.Marshaller.initialize(Marshaller.java:393)
at org.exolab.castor.xml.Marshaller.<init>(Marshaller.java:354)
at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:662)
at XMLJavaBinding.TestBinding.main(TestBinding.java:31)
Exception in thread "main"

<snip code>
You're missing
org/apache/xml/serialize/XMLSerializer

This class is part of the Xerces parser. You can find it at
http://xml.apache.org/xerces2-j/

You'll have to put Xerces in your classpath so the required class can be
loaded.
 
S

Steve W. Jackson

:Hi All,
:
:I am working on Java Binding using Castor. I got the following runtime
:error while i ran the code.
:
:java.lang.NoClassDefFoundError: org/apache/xml/serialize/XMLSerializer
: at org.exolab.castor.xml.Marshaller.initialize(Marshaller.java:393)
: at org.exolab.castor.xml.Marshaller.<init>(Marshaller.java:354)
: at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:662)
: at XMLJavaBinding.TestBinding.main(TestBinding.java:31)
:Exception in thread "main"
:
:
:The code is
:
:package XMLJavaBinding;
:
:/**
: * @author rsanka
: *
: * To change the template for this generated type comment go to
: * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and
:Comments
: */
:
:import java.io.*;
:import org.exolab.castor.xml.*;
:
:public class TestBinding {
:
: public static void main(String[] args) {
: FlightBean bean = new FlightBean ();
: bean.setCarrier ("Lufthansa");
: bean.setNumber (426);
: bean.setDepartureTime ("6:30a");
: bean.setArrivalTime ("8:45a");
:
: try {
: File file = new File ("test.xml");
: Writer writer = new FileWriter (file);
: Marshaller.marshal (bean, writer);
:
: Reader reader = new FileReader (file);
: FlightBean read = (FlightBean) Unmarshaller.unmarshal
:(FlightBean.class, reader);
: System.out.println ("Flight " + read.getCarrier () + read.getNumber
:() + " departing at " +
: read.getDepartureTime () + " and arriving at " +
:read.getArrivalTime ());
: } catch (IOException ex) {
: ex.printStackTrace (System.err);
: } catch (MarshalException ex) {
: ex.printStackTrace (System.err);
: } catch (ValidationException ex) {
: ex.printStackTrace (System.err);
: }
: }
:}
:
:Kindly provide me with the work around..
:
:Thanks,
:Raghu

I can't be completely certain without tons more code, but I have a
possible solution based on what hit my efforts.

As of about 1.3, Sun included some of org.apache.xml and subordinate
packages into the JDK itself. When that happened, we began experiencing
problems with compiling and executing where packages and/or classes
couldn't be found. It turned out that we had to force both the compile
and execution to put the Xerces and Xalan classes before Sun's own in
our command lines. I suspect this in your post because the error refers
to the org.apache.xml.serialize package, which isn't in the JDK.

In the javac command, we did this by using -bootclasspath. But the
problem is that we had to specify the jar files for our Xerces and Xalan
materials and then also specify the rt.jar file in the JDK's own
directory (which was helped by using a JAVA_HOME environment variable).

In the java command, it's a little easier, since you can instead use
"-Xbootclass/p:" to tell it to "prepend" certain jar files to the
automatically understood bootclasspath. So we merely specified the
Xerces and Xalan jars we needed, and it automatically knew to put those
before the rt.jar and any others.

Maybe this will be of help.

= Steve =
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top