已在lib目录下导入xmlbeans 包,但运行显示缺少xmlbeans包

错误信息:
读取docx文件时XWPFWordExtractor(OPCPackage)错误
Multiple markers at this line
- The constructor XWPFWordExtractor(OPCPackage) refers to the missing type XmlException
- The type org.apache.xmlbeans.XmlException cannot be resolved. It is indirectly referenced from
required .class files
错误信息The constructor XWPFWordExtractor(OPCPackage) refers to the missing type XmlException
原因:缺少xmlbeans包

源代码:

package com.test;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.hwpf.HWPFDocument;

public class Test {
    public void readDoc(String path) throws IOException {
        File f = new File(path);
        InputStream is = new FileInputStream(f);
        HWPFDocument  doc = new HWPFDocument(is);
        System.out.println(doc.getDocumentText());
    }
    
    public static void main(String[] args) {
        Test t = new Test();
        try {
            t.readDoc("C:/Users/Administrator/Desktop/test.doc");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}



在lib里面有不等于加到了项目,鼠标右键点击项目名称-》Build Path->Confirgure Build Path,查看列表里面有没有jar

img

可能缺少其他jar包,或者你这个jar包有问题。

试试这篇文章做法;https://blog.csdn.net/weixin_42243829/article/details/82415521

应该是poi和beans这个两个版本不匹配,你可以尝试使用更高级的poi或者降低beans版本;
推荐使用这个版本试一下,这个ooxml里面已经包含xmlbeans了:

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>4.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>4.1.0</version>
        </dependency>

换个版本试试

用idea吧

第一步 ad as library 再次编译一下看看还报错吗?
如果还报错,那么
第二步,检查一下编译后生成的包中是否有这个 包, 如果没有,那么将这个包直接复制到编译后的包中;
如果继续报错,
第三步,那么可能是选择的包不对;
欢迎采纳哦!

看看路径是否加对,路径不对是读取不了的

用maven 加载吧

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>4.1.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>4.1.0</version>
    </dependency>