JBOSS Only Error: java.lang.NoClassDefFoundError: Could not initialize class org.apache.poi.ooxml.util.DocumentHelper

huangapple go评论85阅读模式
英文:

JBOSS Only Error: java.lang.NoClassDefFoundError: Could not initialize class org.apache.poi.ooxml.util.DocumentHelper

问题

使用Apache POI创建Workbook对象来处理输入流时,我开始收到以下错误:

java.lang.NoClassDefFoundError: Could not initialize class org.apache.poi.ooxml.util.DocumentHelper

我经过了代码并发现它发生在ContentTypeManager.class的此代码段中(来自org.apache.poi.openxml4j.opc.internal):

private void parseContentTypesFile(InputStream in) throws InvalidFormatException {
    try {
        Document xmlContentTypetDoc = DocumentHelper.readDocument(in);
        NodeList defaultTypes = xmlContentTypetDoc.getDocumentElement().getElementsByTagNameNS("http://schemas.openxmlformats.org/package/2006/content-types", "Default");
        int defaultTypeCount = defaultTypes.getLength();
        // 其他代码...

所以这一行DocumentHelper.readDocument(in)使用了javax.xml.parsers.DocumentBuilder,这就是问题最终出现的地方,它无法创建DocumentBuilder。我尝试删除xercesImpl但没有效果。

<dependency>
    <groupId>xerces</groupId>
    <artifactId>xercesImpl</artifactId>
    <version>2.12.1</version>
</dependency>

这段代码在WildFly服务器上成功运行,但在JBOSS下失败。我们正在迁移到WildFly,但与此同时,生产环境仍在运行JBOSS。

有关如何解决错误的想法吗?该项目还具有tika-core和tika-parsers-standard-package的依赖项,不确定是否会在JBOSS下引起问题。以前在JBOSS下曾经正常工作。

更新:我的POM文件中有与该问题相关的这些条目:

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>5.2.2</version>
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>5.2.2</version>
</dependency>
<dependency>
    <groupId>xerces</groupId>
    <artifactId>xercesImpl</artifactId>
    <version>2.12.2</version>
</dependency>
<dependency>
    <groupId>org.apache.tika</groupId>
    <artifactId>tika-core</artifactId>
    <version>2.7.0</version>
</dependency>
<dependency>
    <groupId>org.apache.tika</groupId>
    <artifactId>tika-parsers-standard-package</artifactId>
    <version>2.7.0</version>
</dependency>

请确保您的JBOSS环境中有所需的依赖项,并检查是否存在与这些依赖项版本兼容的问题。希望这对您有所帮助。

英文:

When using Apache POI to create a Workbook object to process an input stream, I started receiving the error:

> java.lang.NoClassDefFoundError: Could not initialize class org.apache.poi.ooxml.util.DocumentHelper

I stepped through and found it occurring on this first line of code in this snippet from the ContentTypeManager.class (from org.apache.poi.openxml4j.opc.internal):

private void parseContentTypesFile(InputStream in) throws InvalidFormatException {
    try {
        Document xmlContentTypetDoc = DocumentHelper.readDocument(in);
        NodeList defaultTypes = xmlContentTypetDoc.getDocumentElement().getElementsByTagNameNS(&quot;http://schemas.openxmlformats.org/package/2006/content-types&quot;, &quot;Default&quot;);
        int defaultTypeCount = defaultTypes.getLength();
        ....

So that line DocumentHelper.readDocument(in) is using the javax.xml.parsers.DocumentBuilder and that is where the issue ultimately is, it is unable to create a DocumentBuilder. I tried removing xercesImpl with no effect.

	&lt;dependency&gt;
		&lt;groupId&gt;xerces&lt;/groupId&gt;
		&lt;artifactId&gt;xercesImpl&lt;/artifactId&gt;
		&lt;version&gt;2.12.1&lt;/version&gt;
	&lt;/dependency&gt;

The code runs successfully using a WildFly server, but fails under JBOSS. We are moving to WildFly but in the meantime production still is running JBOSS.

Any thoughts on how to resolve the error? The project also has tika-core and tika-parsers-standard-package dependencies and not sure if those are causing an issue under JBOSS. Previously this had been working under JBOSS.

Update: My POM has these entries that are connected to issue:

	&lt;dependency&gt;
		&lt;groupId&gt;org.apache.poi&lt;/groupId&gt;
		&lt;artifactId&gt;poi&lt;/artifactId&gt;
		&lt;version&gt;5.2.2&lt;/version&gt;
	&lt;/dependency&gt;
	&lt;dependency&gt;
		&lt;groupId&gt;org.apache.poi&lt;/groupId&gt;
		&lt;artifactId&gt;poi-ooxml&lt;/artifactId&gt;
		&lt;version&gt;5.2.2&lt;/version&gt;
	&lt;/dependency&gt;
	&lt;dependency&gt;
		&lt;groupId&gt;xerces&lt;/groupId&gt;
		&lt;artifactId&gt;xercesImpl&lt;/artifactId&gt;
		&lt;version&gt;2.12.2&lt;/version&gt;
	&lt;/dependency&gt;
	&lt;dependency&gt;
		&lt;groupId&gt;org.apache.tika&lt;/groupId&gt;
		&lt;artifactId&gt;tika-core&lt;/artifactId&gt;
		&lt;version&gt;2.7.0&lt;/version&gt;
	&lt;/dependency&gt;
	&lt;dependency&gt;
		&lt;groupId&gt;org.apache.tika&lt;/groupId&gt;
		&lt;artifactId&gt;tika-parsers-standard-package&lt;/artifactId&gt;
		&lt;version&gt;2.7.0&lt;/version&gt;
	&lt;/dependency&gt;

答案1

得分: 0

所以我找出了问题,并想要跟进。为了使应用在WildFly下运行,我不得不添加一些日志排除,因为在WildFly中,已经有一些存在于类路径上的日志记录器会引起冲突。然而,在JBOSS中运行时,似乎应用程序的所有部分都能正常工作,除了POI,因为DocumentBuilder在类路径上找不到所需的日志依赖。一旦我在JBOSS的POM中恢复了日志排除,问题就得到解决。

英文:

So I figured out the issue and wanted to follow-up. In order to get the apps running under WildFly and I had to add some logging exclusions because with WildFly there are already loggers on the classpath that cause conflicts. However, when running in JBOSS all parts of the application worked apparently except for POI because DocumentBuilder couldn't find the needed logging dependency on the classpath. Once I reverted the logging exclusions in the POM for JBOSS, it resolved the issue.

huangapple
  • 本文由 发表于 2023年3月7日 20:12:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/75661831.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定