当我在命令行中运行jar时,JAXB解组返回空属性。
File file = new File("oozie1.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(com.ClassGen.ObjectFactory.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
Source source = new StreamSource(file);
JAXBElement<com.ClassGen.COORDINATORAPP> root = jaxbUnmarshaller.unmarshal(source, com.ClassGen.COORDINATORAPP.class);
com.ClassGen.COORDINATORAPP obj3 = root.getValue();
obj3.getAction(); // This returns a null. But works fine with eclipse. With Eclipse it returns an ACTION object.
你知道怎么回事吗?
谢谢,
Mahalakshmi
尝试检查该文件是否存在。问题可能是找不到文件。
File file = new File("oozie1.xml");
if(file.exists())
{
// your code
}