maven - 如何通过代理使用 Maven?

标签 maven proxy

我想分享一下我通过代理使用maven的经验。

您很可能会遇到异常和消息,例如:

repository metadata for: 'org.apache.maven.plugins' could not be retrieved from 
repository: central due to an error: Error transferring file: Connection refused: connect

[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-clean-
plugin:2.5: Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its 
dependencies could not be resolved: Failed to read artifact descriptor for 
org.apache.maven.plugins:maven-clean-plugin:jar:2.5

如何配置Maven使用代理服务器?

最佳答案

有关为 Maven 设置代理的详细信息,请参阅 mini guide .

本质上,您需要确保全局设置 ([maven install]/conf/settings.xml) 或用户设置 (${user.home}/.m2/settings.xml)配置正确。最好在您的用户设置中执行此操作,以避免将密码以纯文本形式存储在公共(public)位置。

Maven 2.1 引入 password encryption ,但我还没有抽出时间来检查加密是否适用于代理设置以及存储库密码(不明白为什么它不会)。

有关信息,您的 settings.xml 中有一个注释掉的代理配置以及有关如何修改它的说明。

根据迷你指南,您的设置应如下所示:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                  http://maven.apache.org/xsd/settings-1.0.0.xsd">
[...]
  <proxies>
    <proxy>
      <active>true</active>
      <protocol>http</protocol>
      <host>proxy.somewhere.com</host>
      <port>8080</port>
      <username>proxyuser</username>
      <password>somepassword</password>
      <nonProxyHosts>www.google.com|*.somewhere.com</nonProxyHosts>
    </proxy>
  </proxies>
[...]
</settings>

关于maven - 如何通过代理使用 Maven?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1251192/

相关文章:

java - 带蓝图的 Camel 代理

apache - Apache 负载均衡器(代理)服务器背后的真实 IP

php - 如何使用 PHP 完全检测代理

authentication - 使用基本身份验证通过 HTTP 代理访问 HTTPS

java - 尝试使用 Maven 在 JOOQ 中实现 EnumConverter 时出错

java - 升级我的 Spring WebFlow 项目以使用 Maven 和 Hibernate4。现在获取 NoSuchMethodException : org. hibernate.cfg.Configuration.addAnnotatedClass

maven - 缺少 Artifact org.springframework.security :spring-security-parent:jar:3. 0.7.RELEASE:compile

javascript - 在客户端模拟 HTTP 请求

java - OneJar 包括 Dr Tuffs 类(class)

android - 从命令行使用不同的 urls/Environment 构建 android 项目