我正在使用 jdk 1.6 并开发了一个可以生成 xml 消息的程序,它工作正常并且我能够生成它。当我在 unix 服务器中部署它时,我得到了 jaxb.bind。marshaller 异常,在 unix 中他们使用的是 jdk 1.5。在我的 xmlgenerated 类中,包在 JRE 中引用 rt.jar,其中所需的包在 unix 服务器的 jdk 1.5 中不可用。可以帮助我们如何解决这个问题。
例外是:java.lang.NoClassDefFoundError: javax/xml/bind/Marshaller
代码是:
`
public JaxbXmlMessageGenerator() {
try {
jaxbContext = JAXBContext.newInstance("generated");
xmlOutputFactory = XMLOutputFactory.newFactory();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
JaxbXmlMessageGenerator jaxbXmlMessageGenerator = new JaxbXmlMessageGenerator();
System.out.println("-- The Transformed XML Message -- \n"+jaxbXmlMessageGenerator.getMessage());
}
public final String getMessage() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty("jaxb.encoding", "UTF-8");
jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
XMLStreamWriter xmlStreamWriter = xmlOutputFactory
.createXMLStreamWriter(baos, (String) jaxbMarshaller
.getProperty(Marshaller.JAXB_ENCODING));
xmlStreamWriter.writeStartDocument((String) jaxbMarshaller
.getProperty(Marshaller.JAXB_ENCODING), "1.0");
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
File file=new File("D:\\eclipse\\file.xml");
ObjectFactory factory = new ObjectFactory();
BaNCSLimitRQPT rqpt = factory.createBaNCSLimitRQPT();
MsgDtlT msgDtlT = factory.createMsgDtlT();
msgDtlT.setMsgLimitType("FC");
msgDtlT.setMsgOUID("0507");
msgDtlT.setMsgTxnCur("USD");
msgDtlT.setMsgUnBlckInd("2");
msgDtlT.setMsgBlckExpiryDays("2");
msgDtlT.setMsgBlckExpiryDayType("1");
msgDtlT.setMsgTenor("180");
msgDtlT.setMsgLimitId("1234");
rqpt.setMsgDtl(msgDtlT);
JAXBElement<BaNCSLimitRQPT> element = factory
.createBaNCSLimitRQP(rqpt);
jaxbMarshaller.marshal(element, file);
jaxbMarshaller.marshal(element, System.out);
xmlStreamWriter.writeEndDocument();
xmlStreamWriter.close();
} catch (Exception e) {
e.printStackTrace();
}
return new String(baos.toByteArray());
} }
`
问候, 拉文达