英文:
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("http://schemas.openxmlformats.org/package/2006/content-types", "Default");
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.
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.12.1</version>
</dependency>
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:
<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>
答案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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论