当我在命令行中运行jar时,JAXB unmarshalling返回null属性。但是在eclipse中可以正常工作。
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.
关于什么是错误的任何想法?
谢谢,
玛哈拉卡斯
答案 0 :(得分:0)
尝试检查文件是否存在。问题可能是找不到文件。
File file = new File("oozie1.xml");
if(file.exists())
{
// your code
}