I am trying to create a simple JAXB program and write the object out to a xml file however its not creating any output - I am pasting sample code and output -
Code -
ObjectFactory fct = new ObjectFactory();
ImportParams imp = fct.createImportParams();
FolderMaps fmaps = fct.createFolderMaps();
FolderMap fmap = fct.createFolderMap();
imp.setFolderMaps(fmaps);
fmap.setSourceFolderPath("test");
fmaps.getFolderMap().add(fmap);
System.out.println("Size is " + fmaps.getFolderMap().size());
System.out.println("Path is " + fmap.getSourceFolderPath());
ImportParams imp1 = new ImportParams();
imp1.setFolderMaps(fmaps);
JAXBContext ctx = null;
System.out.println("Writing JAXB objects");
try {
ctx = JAXBContext.newInstance("com.au");
System.out.println("Inside JAXB");
Marshaller marshaller = ctx.createMarshaller();
System.out.println("Marshal Started");
marshaller.marshal(fmaps, System.out);
marshaller.marshal(imp, System.out);
marshaller.marshal(fmap, System.out);
System.out.println("Marshal Completed");
marshaller.marshal(fmaps, new File ("C:\\Users\\test\\Desktop\\eclipse_workspace_64\\abcjaxb.xml"));
} catch (Exception e) {
// TODO: handle exception
}
Output is
Size is 1
Path is test
Writing JAXB objects
Inside JAXB
Marshal Started
Parameter file successfully created
Its terminating after marshal started and not creating the xml file
You need to add @XmlRootElement
to your com.au.FolderMap
class, eg
package com.au;
@XmlRootElement
public class FolderMap {
// ...
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.