samedi 7 mars 2015

Getting error in compiling java code involving JAXB


Vote count:

0




I am trying to convert java object into a XML file using JAXB, but getting following errors in code.



import java.io.File;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

public class JAXBExample{

public static void main(String[] args){

Customer customer = new Customer();
customer.setId(100);
customer.setName("fahad akber");
customer.setAge(32);

try{

File file = new File("C:\\XMLFile.xml");
JAXBContext = jaxbContext = JAXBContext.newInstance(Customer.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();


jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true);

jaxbMarshaller.marshal(customer,file);
jaxbMarshaller.marshal(customer,System.out);
} catch (JAXBException e){
e.printStackTrace();
}
}
}


Note:



  • here i am not using any java IDE, for code execution, just windows command prompt

  • both files (Customer.java and JAXBExample.java) are placed in same directory.

  • i m using java version -


C:\Users\Administrator>java -version java version "1.6.0_33" Java(TM) SE Runtime Environment (build 1.6.0_33-b05) Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03, mixed mode)


Thanks, Fahad



asked 19 secs ago







Getting error in compiling java code involving JAXB

Aucun commentaire:

Enregistrer un commentaire