Exception in thread "main" java.lang.NoSuchMethodError: org.apache.xmlbeans.XmlOptions.setSaveAggressiveNamespaces()Lorg/apache/xmlbeans/XmlOptions;
at org.apache.poi.POIXMLDocumentPart.<clinit>(POIXMLDocumentPart.java:56)
at rulebooksToExcel.GenerateExcel.generateExcel(GenerateExcel.java:34)
at rulebooksToExcel.ParseNortDocFiles.main(ParseNortDocFiles.java:165)
I am getting the error at :
workbook = new XSSFWorkbook(in);
I read other similar questions but they all suggest XMLBeans Version 2.0+. But I am using 2.6, and I can't find any other explanation for what might be causing this.
I bumped into the same error in Java8.
This accepted answer helped me out:
I added the following lines to my code:
It turned out that if you use Java8 JRE to run your application, you got this in the log: XmlOptions.class loaded from file:/C:/Program%20Files/Java/jre1.8.0_131/lib/ext/xbean.jar!/org/apache/xmlbeans/XmlOptions.class
So in Java8, there is a apache xmlbeans jar in the JRE/lib/ext that will be loaded first regardless of your classpath settings!
When I changed the JAVA_HOME/PATH to point to my installed JDK8, the problem solved.
After a short check this is true for JRE7 too. The problem is that the JRE-bundled xbean.jar contains XmlOptions::setSaveAggresiveNamespaces (with one 's') in both cases.
(My used POI version was 3.17 because this version is compatible with Java7.)
Update: it turned out that this was true in my corporate env (prepared machine/group policy), at home on my PC there is no such jar.