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 de or 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

解决方法:
在项目的pom. 中指定私服中央仓库的url(其中host是你私服的ip,post是你私服的端口,如果不知道,可以找到settings. 文件,一般在开发网下,都会配置maven指定私服中央仓库下载)即可让项目去指定的仓库下载jar

<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>
收藏 打印