1

我正在使用 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());
} } 

`

问候, 拉文达

4

1 回答 1

1

我在 jdk 1.5 中实施时遇到了 JAXB 的问题。在 unix 服务器中部署的 Jaxb 异常

我在 maven 项目中实现了如下所示的相同。

<plugin> 
                            <groupId>org.jvnet.jaxb2.maven2</groupId> 
                            <artifactId>maven-jaxb2-plugin</artifactId> 
                            <version>0.8.1</version> 
                            <dependencies> 
                                    <dependency> 
                                            <groupId>javax.xml.bind</groupId> 
                                            <artifactId>jaxb-api</artifactId> 
                                            <version>2.1</version> 
                                    </dependency> 
                            </dependencies> 
                            <executions> 
                                    <execution> 
                                            <id>xsd-generate</id> 
                                            <goals> 
                                                    <goal>generate</goal> 
                                            </goals> 
                                            <configuration> 
                                                    <generateDirectory>src/main/java</generateDirectory> 
                                                    <generatePackage>com.db.accounting.application.server.jaxbautogenerated</generatePackage> 
                                                    <schemaDirectory>src/main/resources</schemaDirectory> 
                                                    <includeSchemas> 
                                                            <include>accounting.xsd</include> 
                                                    </includeSchemas> 
                                                    <extension>true</extension> 
                                                    <plugins> 
                                                            <plugin> 
                                                                    <groupId>org.jvnet.jaxb2_commons</groupId> 
                                                                    <artifactId>jaxb2-basics</artifactId> 
                                                                    <version>0.5.3</version> 
                                                            </plugin> 
                                                    </plugins> 
                                            </configuration> 
                                    </execution> 
                            </executions> 
                    </plugin> 
于 2013-12-12T09:11:54.927 回答