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

Apache Commons FileUpload 1.5升级至1.6.0的编译问题解决咨询(无法使用Jakarta库)

Apache Commons FileUpload 1.5升级至1.6.0的编译问题解决咨询(无法使用Jakarta库)

我目前遇到了一个依赖升级后的编译问题,想请教大家该怎么解决:

背景与核心限制

我维护着一个Maven项目,之前使用commons-fileupload 1.5版本完全正常,但升级到1.6.0后编译直接失败。这里有个绕不开的核心限制:因为后续依赖了org.gwtproject,我完全不能在代码中使用Jakarta相关的库。

当前配置文件的迁移情况

pom.xml 依赖配置

<dependency>
    <groupId>commons-fileupload</groupId><!-- poi excel does not like u! -->
    <artifactId>commons-fileupload</artifactId>
    <exclusions>
        <exclusion>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
        </exclusion>
    </exclusions>
    <version>1.6.0</version><!-- 1.5 was working -->
</dependency>

(注:我单独引入了commons-io 2.19.0版本,所以在这里排除了fileupload自带的commons-io依赖)

module-info.java 配置

requires org.apache.commons.fileupload;//commons.fileupload;

编译命令与错误详情

我在NetBeans中执行的编译命令如下:

cd C:\git\blg\com.tugalsan.blg.org_apache_commons_fileupload_1_6_0; 
JAVA_HOME=C:\\bin\\java\\home 
cmd /c "\"C:\\bin\\netbeans\\home\\java\\maven\\bin\\mvn.cmd\" -Dmaven.ext.class.path=C:\\bin\\netbeans\\home\\java\\maven-nblib\\netbeans-eventspy.jar --no-transfer-progress clean install"

编译时先弹出了一个警告:

Required filename-based automodules detected: [javax.servlet-api-4.0.1.jar]. Please don't publish this project to a public artifact repository!

随后触发了3个关键编译错误:

COMPILATION ERROR : 
-------------------------------------------------------------
com/tugalsan/blg/org_apache_commons_fileupload_1_6_0/server/TS_SUploadWebServlet.java:[113,51] cannot access javax.servlet.ServletContextListener
class file for javax.servlet.ServletContextListener not found
com/tugalsan/blg/org_apache_commons_fileupload_1_6_0/server/TS_SUploadWebServlet.java:[48,35] cannot access javax.servlet.http.HttpServletRequest
class file for javax.servlet.http.HttpServletRequest not found
com/tugalsan/blg/org_apache_commons_fileupload_1_6_0/server/TS_SUploadWebServlet.java:[55,73] no suitable method found for parseRequest(javax.servlet.http.HttpServletRequest)
method org.apache.commons.fileupload.FileUploadBase.parseRequest(org.apache.commons.fileupload.RequestContext) is not applicable
  (argument mismatch; javax.servlet.http.HttpServletRequest cannot be converted to org.apache.commons.fileupload.RequestContext)
method org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(javax.servlet.http.HttpServletRequest) is not applicable
  (argument mismatch; javax.servlet.http.HttpServletRequest cannot be converted to javax.servlet.http.HttpServletRequest)

额外说明

在NetBeans的项目依赖列表中,我能确认javax.servlet-api-4.0.1.jar、commons-fileupload-1.6.0.jar、commons-io-2.19.0.jar这几个依赖都已经正常存在。

我的问题

请问我需要做哪些代码变更,才能在完全不使用Jakarta库的前提下,顺利完成commons-fileupload从1.5到1.6.0的迁移并解决这些编译错误?


内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.08 08:53:03