开发网下,maven install 时去maven中央仓库下载jar,访问超时

在开发网环境下,由于无法访问maven中央仓库,执行maven install时遇到依赖下载超时问题。为了解决这个问题,可以将pom.xml或settings.xml文件中指向中央仓库的URL替换为内网或私服的URL,确保项目能够从指定仓库成功下载所需jar包。此方法对当前或所有pom.xml配置生效。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

maven install 时出现下面的异常信息

[ERROR] Failed to execute goal on project xxx: Could not resolve dependencies for project xxx.jar:1.0.3-SNAPSHOT: Failed to collect dependencies for [junit:junit:jar:3.8.1 (test), org.apache.ibatis:ibatis-sqlmap:jar:2.3.4.726 (compile), mysql:mysql-connector-java:jar:5.1.13 (compile), c3p0:c3p0:jar:0.9.1.2 (compile), com.google.code.gson:gson:jar:2.3.1 (compile), org.slf4j:slf4j-api:jar:1.7.7 (compile)]: Failed to read artifact descriptor for org.slf4j:slf4j-api:jar:1.7.+: Could not transfer artifact org.slf4j:slf4j-api:pom:1.7.+ from/to central (http://repo.maven.apache.org/maven2): connection timed out to http://repo.maven.apache.org/maven2/org/slf4j/slf4j-api/1.7.+/slf4j-api-1.7.+.pom -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

原因:
因为是开发网,无法访问maven中央仓库,把指向中央仓库central的url改为私服的中央仓库

解决方法:
在项目的pom.xml中指定私服中央仓库的url,即可让项目去指定的仓库下载jar,但只是对当前配置的pom.xml生效
如果想要一次配置,以后所有的pom.xml都生效,可以配置到setting.xml中

<repositories>
    <repository>
        <id>central</id>
        <url>http://host:post/nexus/content/groups/public</url>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>central</id>
        <url>http://host:post/nexus/content/groups/public</url>
    </pluginRepository>
</pluginRepositories>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值