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

PDFBox 3.0加载PDF出现LogFactory缺失的ClassNotFoundException求助

解决PDFBox 3.0运行时ClassNotFoundException(缺失org.apache.commons.logging.LogFactory)

问题原因

你遇到的java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory是因为PDFBox 3.0依赖Apache Commons Logging组件,但当前项目的依赖中缺少这个必要的jar包。

解决方案

方法一:手动添加依赖jar包

  • 下载与PDFBox 3.0.0-alpha3兼容的commons-logging jar包(推荐版本1.2及以上)
  • 打开Eclipse,右键项目 → 选择Build Path → Add External Archives
  • 选中下载好的commons-logging-x.x.x.jar,将其添加到项目的Modulepath中
  • 重新运行项目

方法二:使用依赖管理工具(推荐)

如果项目使用Maven或Gradle,直接添加对应依赖即可自动处理所有依赖关系:

  • Maven:在pom.xml中添加
<dependency>
    <groupId>org.apache.pdfbox</groupId>
    <artifactId>pdfbox</artifactId>
    <version>3.0.0-alpha3</version>
</dependency>
  • Gradle:在build.gradle中添加
implementation 'org.apache.pdfbox:pdfbox:3.0.0-alpha3'

依赖管理工具会自动下载PDFBox及其所有关联依赖(包括Commons Logging)。

验证示例

添加依赖后,重新运行PDF加载代码(注意用完文档后关闭资源):

File pdfFile = new File("C:\\Users\\SchroeT\\myPDF.pdf");
System.out.println("\n\nFile: " + pdfFile);
PDDocument doc = Loader.loadPDF(pdfFile);
// 业务逻辑处理
doc.close();

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 02:30:52