5
votes

I am trying to generate Excel using Xssf API because its memory footprint is small. It is working fine in my local machine which is having jdk1.7. But when I try to run it on UNIX where java version is 1.6.0_75 it gives me the following error.

java.lang.NoClassDefFoundError: Could not initialize class org.apache.poi.openxml4j.opc.internal.marshallers.ZipPackagePropertiesMarshaller

I have following jars in my classpath

  • poi-3.11-20141221.jar
  • poi-excelant-3.11-20141221.jar
  • poi-ooxml-3.11-20141221.jar
  • poi-ooxml-schemas-3.11-20141221.jar
  • xmlbeans-2.6.0.jar
  • xercesImpl.jar

I have verified that poi-3.11-20141221.jar has the ZipPackagePropertiesMarshaller class.

Seems that some jar is missing. Am I missing something?

2

2 Answers

4
votes

I have found a solution to my own problem. I replaced poi-3.11-20141221.jar with poi-ooxml-3.9.jar. That worked.

1
votes

Java version 1.6.0_75 does not exists, I suppose you make a typo. The last update of Java 6 is the update 45 (6u45).

The class ZipPackagePropertiesMarshaller is loaded at run-time for sure. The exception NoClassDefFoundError occurs during the initialization phase; if the exception had been ClassNotFoundException, it would have been different...

The class ZipPackagePropertiesMarshaller is unaltered between the versions 3.11 and 3.9, but the class PackagePropertiesMarshaller extended by ZipPackagePropertiesMarshaller is changed: the main change regards the use of StAX in the newer version.

The distribution of StAX coming with Java 6, but the version of Java 6 update 18 (http://www.oracle.com/technetwork/java/javase/6u18-142093.html) introduces the StAX 1.2 API version.

Consider to use Java 6u18 or newer. This should solve your problem.

In the official FAQ there are some indications about a similar problem: https://poi.apache.org/faq.html#faq-N1017E.

Moreover, the workaround you found is not the best one, see the last FAQ of POI.