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

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>centralid>
        <url>http://host:post/nexus/content/groups/publicurl>
    repository>
repositories>

<pluginRepositories>
    <pluginRepository>
        <id>centralid>
        <url>http://host:post/nexus/content/groups/publicurl>
    pluginRepository>
pluginRepositories>

你可能感兴趣的:(maven)