[英]JAXB Marshall not output XML
我正在嘗試創建一個簡單的JAXB程序並將該對象寫到xml文件中,但是它沒有創建任何輸出-我正在粘貼示例代碼和輸出-
代碼-
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
}
輸出是
Size is 1
Path is test
Writing JAXB objects
Inside JAXB
Marshal Started
Parameter file successfully created
元帥啟動后終止,並且不創建xml文件
您需要將@XmlRootElement
添加到com.au.FolderMap
類,例如
package com.au;
@XmlRootElement
public class FolderMap {
// ...
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.