java.lang.NoClassDefFoundError: Could not initialize class org.apache.poi.POIXMLDocument on Jboss 5.0 EAP
Asked Answered
D

4

6

Getting following exception in Jboss 5.0 EAP but it work fine in JBoss 5.1 GA.

we are using POI 3.7 and jars included are

  • poi-3.7.jar
  • poi-ooxml-schemas.jar
  • poi-ooxml.jar

The stack trace is

ERROR [org.apache.catalina.core.ContainerBase.[jboss.ueb].[localhost].[fesbcon-Fig].[Faces Servlet]]
    3;13;44.4g3pM (http-0.0.0.0-8280-1) Servlet.service() -For servlet Faces Servlet threu exception
    java.lang.NoClassDe-FFoundError: Could not initialize class org.apache.poi.POIXMLDocument
    at org.apache.poi.ss.usermodel.HorkbookFactory.create(HorkbookFactory.java:62)
    at com.-Ferguson.esb.con-Fig.controller.AssociationsExcelUploadController.submit(Unknoun Source)
    at sun.re-Flect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.re-Flect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.re-Flect.DelegatingMethodAccessorImpl.invoke(Delegating?ethodAccessorImpl.java:25)
    at java.lang.re-Flect.Method.invoke(Method.java:597)
    at org.apache.my-Faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:132)
    at org.apache.my-Faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:61)

Please Advise how to solve this issue in JBoss 5.0 EAP

Dinky answered 8/11, 2012 at 7:38 Comment(2)
Is it me or does that stacktrace look like it's an OCR scan of a screenshot of a stacktrace?Bounteous
@LukeWoodward Yes it's an OCR ScanDinky
B
12

It looks like you're application is throwing the exception you're seeing because an Apache XMLBeans JAR or class is not present when running under JBoss 5.0. It seems Apache POI is trying to load the class org.apache.xmlbeans.XMLOptions but it cannot find this class.

The message Could not initialize class SomeClass indicates that the JVM has twice tried and failed to load and statically initialize the class SomeClass. In this case, the class in question is org.apache.poi.POIXMLDocument.

Static initialization for a class consists of statically initializing its superclass, assigning values to all static fields and running all static initializer blocks. The POIXMLDocument class has a few static String constants, which won't cause any problem, but no static initializer. It is however a subclass of POIXMLDocumentPart, which is a subclass of Object and which has the following static initialization code:

    private static POILogger logger = POILogFactory.getLogger(POIXMLDocumentPart.class);

    public static final XmlOptions DEFAULT_XML_OPTIONS;
    static {
        DEFAULT_XML_OPTIONS = new XmlOptions();
        DEFAULT_XML_OPTIONS.setSaveOuter();
        DEFAULT_XML_OPTIONS.setUseDefaultNamespace();
        DEFAULT_XML_OPTIONS.setSaveAggressiveNamespaces();
    }

This static initialization will fail if the JVM cannot load all of the POILogger, POILogFactory and XmlOptions classes.

The POILogger and POILogFactory classes are both imported from the package org.apache.poi.util.POILogFactory, and both classes are contained within poi-3.7.jar, so they're not the problem here. So, by elimination, it seems the XmlOptions class, imported from org.apache.xmlbeans.XmlOptions, must be missing.

I found this XMLOptions class within xbean.jar contained within the lib folder of xmlbeans-2.6.0.zip downloadable from one of the mirrors here.

It seems likely to me that adding this JAR will fix the problem on JBoss 5.0 EAP. However, I'm aware you said your application works fine in JBoss 5.1 GA, which implies to me that JBoss 5.1 GA contains a copy of this JAR whereas 5.0 EAP doesn't. As a result I'm not sure what the best way to fix this problem is. I'd be hesitant to add this XMLBeans JAR to your application as doing so may cause issues when you run it under JBoss 5.1. I don't know whether there's a way of adding extra 'library' JARs to JBoss 5.0, though - perhaps that's worth looking at?

Bounteous answered 8/11, 2012 at 12:13 Comment(3)
Link ain't working. Oh it was posted in 2012Hawley
@CharithJayasanka: If you're still using JBoss 5.0 in 2023, you can of course download the XMLBeans JAR from xmlbeans.apache.org/download/index.html, which a quick Google will find. I wouldn't recommend XMLBeans version 2.6.0 though, given that it has a security vulnerability.Bounteous
I'm using tomcat 9Hawley
T
5

I had the same error running on JBoss 8.2 (WildFly 8.2.0.Final) with Apache POI 3.14

Error:

Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.apache.poi.POIXMLTypeLoader

I fixed this by including the latest xmlbeans-2.6.0 jar (I previously had 2.4.0) into my deployment which is included with the Apache POI 3.14 distribution in the ooxml-lib folder.

Truss answered 8/7, 2016 at 15:29 Comment(1)
I had the same error with poi-4.0.1. And fixed by upgrade xmlbeans to 3.0.2 .Jaimiejain
H
3

Placing the Following jars in classpath will do the trick:

  • dom4j-1.6.1.jar

  • poi-3.9-20121203.jar

  • poi-ooxml-3.9-20121203.jar

  • poi-ooxml-schemas-3.9-20121203.jar

  • xmlbeans-2.3.0.jar

Hyperthermia answered 3/12, 2016 at 13:14 Comment(1)
This is also worked for me when org.apache.poi.xwpf.usermodel.XWPFDocument was missing. Thanks.Baribaric
M
1

By adding only the xbean.jar alone, you can not solve the problem. It will continue complaining class not found. What I did is import not only xbean.jar but also other jar files which are listed under lib folder of xmlbeans-2.5.0

Mainly answered 8/2, 2013 at 10:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.