如何设置maven代理

时间:2013-08-01 08:41:19

标签: maven proxy

我尝试在NetBeans 7.4中设置maven代理,因为我在代理后面。我在NetBeans中通过工具>选项>常规>代理设置设置代理,并且它正常工作。但是当我尝试构建项目时,我仍然遇到错误。

Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.5: Could not transfer artifact org.apache.maven.plugins:maven-resources-plugin:pom:2.5 from/to central (http://repo.maven.apache.org/maven2): repo.maven.apache.org: Unknown host repo.maven.apache.org -> [Help 1]

我搜索了错误消息,然后在maven的settings.xml文件中设置了相同的代理,但又出现了错误。

Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.5: Could not transfer artifact org.apache.maven.plugins:maven-resources-plugin:pom:2.5 from/to central (http://repo.maven.apache.org/maven2): Not authorized by proxy , ReasonPhrase:Proxy Authentication Required. -> [Help 1]

有谁知道错误是什么?

添加代理设置:

<proxies>
    <!-- proxy
     | Specification for one proxy, to be used in connecting to the network.
     |-->
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>proxyhost</host>
      <port>8080</port>
      <nonProxyHosts>localhost|*.google.com.*</nonProxyHosts>
    </proxy>
       </proxies>

3 个答案:

答案 0 :(得分:7)

它可能是一个NTLM代理?如果是:

从中下载wagon-http-lightweight-2.2.jar http://repo.maven.apache.org/maven2/org/apache/maven/wagon/wagon-http-lightweight/2.2/wagon-http-lightweight-2.2.jar

将wagon-http-lightweight-2.2.jar复制到%M2_HOME%/ lib / ext文件夹。

答案 1 :(得分:1)

正如你所说。您正在使用NetBean作为IDE。请检查IDE中使用的maven。也许你正在使用嵌入式maven插件。那么即使你改变

下的settings.xml它也行不通
  

/Users/username/.m2/settings.xml

答案 2 :(得分:1)

在$ MAVEN_HOME / conf文件夹中的settings.xml文件中设置代理,或者在存储settings.xml文件时设置代理。

在settings.xml中,添加此部分(可以添加到<settings></settings>内的任何位置:

<proxies>
 <proxy>
    <id>example-proxy</id>
    <active>true</active>
    <protocol>http</protocol>
    <host>172.20.201.42</host>   <!-- add your proxy host IP here -->
    <port>8080</port> <!-- add your proxy host port here -->
    <nonProxyHosts>  <!-- non proxy hosts separated by | (pipe) character -->
      172.*|10.*
    </nonProxyHosts>
  </proxy>
</proxies> 

您可以在此处找到有关代理的maven文档:

https://maven.apache.org/guides/mini/guide-proxies.html