Java.lang.NoClassDefFoundError: failed to initialize class org.apache.poi.openxml4j.opc.internal.marshallers.ZipPackagePropertiesMarshaller

I am trying to create Excel using the Xssf API because its memory size is small. It works fine on my local machine, which has jdk1.7. But when I try to run it on UNIX, where the 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 the following jars in my classpath

  • poi-3.11-20141221.jar
  • poi-excelant-3.11-20141221.jar
  • poi-OOXML-3.11-20141221.jar
  • poi-OOXML-scheme-3.11-20141221.jar
  • XMLBeans-2.6.0.jar
  • xercesImpl.jar

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

It seems that some kind of jug is missing. Did I miss something?

+5
source share
2 answers

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

+4
source

Java version 1.6.0_75 does not exist, I suppose you are making a typo. The latest Java 6 update is update 45 (6u45).

The ZipPackagePropertiesMarshaller class is loaded at run time. The NoClassDefFoundError exception occurs during the initialization phase; if the exception was a ClassNotFoundException, that would be different ...

The ZipPackagePropertiesMarshaller class does not change between versions 3.11 and 3.9, but the PackagePropertiesMarshaller class extended by ZipPackagePropertiesMarshaller changes: the main change concerns the use of StAX in the newer version.

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

Suppose you use Java 6u18 or later. This should solve your problem.

The official FAQ has some guidance on a similar issue: https://poi.apache.org/faq.html#faq-N1017E .

Also, the workaround you found is not the best, see the latest FAQ for POI.

+1
source

Source: https://habr.com/ru/post/1211973/


All Articles