Reputation: 21
I am using the jdk 1.6 and developed one programe which can generate the xml message, its working fine and i am able to genearate it. when i deploy it in the unix server i am getting the jaxb.bind. marshaller exception where as in unix they were using the jdk 1.5. in my xmlgenerated class, the packages are refering rt.jar in the JRE where the required package is not available in the jdk 1.5 in unix server. Can any help how can we achieve this issue.
The exception is : java.lang.NoClassDefFoundError: javax/xml/bind/Marshaller
The code is :
`
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());
} }
`
Regards, Ravindar
Upvotes: 1
Views: 164
Reputation: 21
I faced a problem with JAXB in imlementing in jdk 1.5. Jaxb exception in deploying in the unix server
I have achived the same as shown in below in maven project.
<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>
Upvotes: 1