You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iText导入报错:The type com.itextpdf.XXX is not accessible 求助

解决iText 7导入报错"The type com.itextpdf.XXX is not accessible"

针对你遇到的问题,尝试以下几个解决方案:

1. 替换聚合POM依赖为具体模块依赖

使用itext7-core聚合POM有时会因模块系统兼容性问题导致包访问权限异常,直接引入所需的具体模块:

<dependencies>
    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>kernel</artifactId>
        <version>7.2.4</version>
    </dependency>
    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>io</artifactId>
        <version>7.2.4</version>
    </dependency>
    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>layout</artifactId>
        <version>7.2.4</version>
    </dependency>
</dependencies>

2. 升级Maven编译器插件并添加模块参数

Java 18搭配低版本编译器插件可能存在兼容性问题,升级插件并添加模块访问参数:

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.11.0</version>
    <configuration>
        <release>18</release>
        <compilerArgs>
            <arg>--add-modules</arg>
            <arg>com.itextpdf.kernel,com.itextpdf.io,com.itextpdf.layout</arg>
        </compilerArgs>
    </configuration>
</plugin>

3. 清理Maven缓存并重新下载依赖

执行以下命令强制更新依赖:

mvn clean install -U

之后在IDE中刷新Maven项目(如IntelliJ的「Reload All Maven Projects」,Eclipse的「Maven -> Update Project」)。

4. 检查IDE依赖配置

  • IntelliJ:打开「Project Structure -> Modules -> Dependencies」,确认iText的jar包状态正常,无红色警告。
  • Eclipse:右键项目 ->「Build Path -> Configure Build Path」,确保iText依赖已正确添加且无报错。

内容的提问来源于stack exchange,提问作者Floran

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 12:15:35