關於網站內容管理這章中Castor的使用

whu發表於2005-03-10
我把下載了castor-0.9.6-xml.jar載入到工程的庫中,使用了下面的例子在JB9中除錯;
public class FlightBean
{
private String m_carrier;
private int m_number;
private String m_departure;
private String m_arrival;

public FlightBean() {}
public void setCarrier(String carrier) {
m_carrier = carrier;
}
public String getCarrier() {
return m_carrier;
}
public void setNumber(int number) {
m_number = number;
}
public int getNumber() {
return m_number;
}
public void setDepartureTime(String time) {
m_departure = time;
}
public String getDepartureTime() {
return m_departure;
}
public void setArrivalTime(String time) {
m_arrival = time;
}
public String getArrivalTime() {
return m_arrival;
}
}


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

public class Test
{
public static void main(String[] argv) {

// build a test bean
FlightBean bean = new FlightBean();
bean.setCarrier("AR");
bean.setNumber(426);
bean.setDepartureTime("6:23a");
bean.setArrivalTime("8:42a");
try {

// write it out as XML
File file = new File("test.xml");
Writer writer = new FileWriter(file);

Marshaller.marshal(bean, writer);

// now restore the value and list what we get
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);
}
}
}
執行的結果是:
D:\JBuilder9\jdk1.4\bin\javaw -classpath "C:\Documents and Settings\ouqichao\jbproject\CastorApp\classes;C:\j2sdk1.4.2_04\lib\castor-0.9.6-xml.jar;D:\JBuilder9\lib\xercesImpl.jar;D:\JBuilder9\lib\xmlParserAPIs.jar;D:\JBuilder9\extras\xalan\bin\xalan.jar;D:\JBuilder9\jdk1.4\demo\jfc\Java2D\Java2Demo.jar;D:\JBuilder9\jdk1.4\demo\plugin\jfc\Java2D\Java2Demo.jar;D:\JBuilder9\jdk1.4\jre\lib\charsets.jar;D:\JBuilder9\jdk1.4\jre\lib\ext\dnsns.jar;D:\JBuilder9\jdk1.4\jre\lib\ext\ldapsec.jar;D:\JBuilder9\jdk1.4\jre\lib\ext\localedata.jar;D:\JBuilder9\jdk1.4\jre\lib\ext\sunjce_provider.jar;D:\JBuilder9\jdk1.4\jre\lib\im\indicim.jar;D:\JBuilder9\jdk1.4\jre\lib\jaws.jar;D:\JBuilder9\jdk1.4\jre\lib\jce.jar;D:\JBuilder9\jdk1.4\jre\lib\jsse.jar;D:\JBuilder9\jdk1.4\jre\lib\rt.jar;D:\JBuilder9\jdk1.4\jre\lib\sunrsasign.jar;D:\JBuilder9\jdk1.4\lib\dt.jar;D:\JBuilder9\jdk1.4\lib\htmlconverter.jar;D:\JBuilder9\jdk1.4\lib\tools.jar" castorapp.Test
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.exolab.castor.util.LocalConfiguration.<clinit>(LocalConfiguration.java:105)
at org.exolab.castor.xml.Marshaller.initialize(Marshaller.java:393)
at org.exolab.castor.xml.Marshaller.<init>(Marshaller.java:350)
at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:704)
at castorapp.Test.main(Test.java:20)
Exception in thread "main"
我想問下使用Castor還需要什麼包作為基礎?謝謝!

相關文章