JAXB unmarshalling返回null属性命令行

时间:2014-06-09 20:08:37

标签: java xml linux shell jaxb

当我在命令行中运行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.

关于什么是错误的任何想法?

谢谢,

玛哈拉卡斯

1 个答案:

答案 0 :(得分:0)

尝试检查文件是否存在。问题可能是找不到文件。

File file = new File("oozie1.xml");
if(file.exists())
{
  // your code
}