无法为maven配置apache poi ooxml

时间:2014-04-02 11:47:53

标签: java excel maven apache-poi sax

需要打开2003格式的XLS和2007+格式的XLSX。 有像

这样的代码
Workbook workbook = WorkbookFactory.create( inputStream );

pom.xml包含:

  • org.apache.poi:poi v3.9
  • org.apache.poi:poi-ooxml v3.9
  • org.apache.poi:ooxml-schemas v1.1

但是用SAX获得例外: Could not initialize a SAX Parser. Please add a SAX parser to your classpath along with preferably jaxp.jar 并且像

这样的代码抛出异常
SAXReader xmlReader = new SAXReader(); //using dom4j library
xmlReader.read(file);

我发现在我的类路径中有两个org.xml.sax.XMLReader类。一个在java 1.7 rt.jar中,另一个在xml-apis:xml-apis工件中。当dom4j尝试创建XMLReader时,它会尝试将其从xml-apis:xml-apis转换为XMLReader,而不是从rt.jar转换。然后失败了。

嗯,我想并从我的pom.xml中的所有隐式依赖项中排除了xml-apis:xml-apis。 然后 - hallelujah - SAXReader工作!

但是另一个例外失败了: 在创建Workbook时,poi-ooxml转到ThemesTable.java:44并执行

theme = ThemeDocument.Factory.parse(part.getInputStream());

java.lang.NoClassDefFoundError抛出消息"无法初始化类org.apache.xmlbeans.XmlBeans"

但是org.apache.xmlbeans:xmlbeans:jar:2.3.0在我的结果jar中! 示例代码失败:

XmlBeans.compilePath( "" );

但如果你认为 - 如果pom.xml中包含xml-apis:xml-apis,它会起作用吗?

帮助,伙计们,如何为ooxml驯服apache.poi?

0 个答案:

没有答案