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

Maven项目配置io.netty依赖后编译提示包不存在问题求助

问题解决方案

核心问题:依赖未实际引入

你在pom.xml里仅在dependencyManagement节点声明了Netty依赖的版本,但没有在dependencies节点中实际引入该依赖。dependencyManagement的作用是统一管理依赖版本,不会自动将依赖添加到项目的类路径中,因此编译时找不到Netty的包。

修复后的pom.xml

可以保留dependencyManagement的版本管理,同时在dependencies节点中引入依赖:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>untitled2</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <repositories>
        <repository>
            <id>central</id>
            <name>Maven Central</name>
            <url>https://repo1.maven.org/maven2/</url>
        </repository>
    </repositories>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>io.netty</groupId>
                <artifactId>netty-all</artifactId>
                <version>4.1.93.Final</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <!-- 新增实际依赖引入,无需重复写版本 -->
    <dependencies>
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-all</artifactId>
        </dependency>
    </dependencies>

</project>

部分依赖无法下载的补充排查

如果修复后Netty、OkHttp3等仍无法正常下载,可尝试以下操作:

  • 确认网络可正常访问Maven中央仓库
  • 执行命令mvn dependency:purge-local-repository清理本地仓库中损坏的依赖缓存,再重新运行mvn clean install -U
  • 检查settings.xml是否存在镜像规则拦截了这些依赖的下载(当前你的配置无异常)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 08:57:26