You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

公司机器配置代理后Maven仍无法下载依赖提示未知主机求助

Fixing Maven "Unknown Host" Error with Working Browser Proxy

Hey there, sorry to hear you're stuck with this frustrating issue—your browsers work perfectly with the company proxy, but Maven just won't play nice. Let's walk through the most likely fixes to get your dependencies downloading again.

1. Double-Check Your settings.xml Proxy Format

First, make sure your proxy configuration in settings.xml is structured correctly. Browsers might be forgiving, but Maven expects precise XML syntax. Here's a solid template to compare against:

<proxies>
  <!-- HTTP Proxy Configuration -->
  <proxy>
    <id>company-http-proxy</id>
    <active>true</active>
    <protocol>http</protocol>
    <host>your-proxy-server</host>
    <port>your-proxy-port</port>
    <username>your-domain\your-username</username>
    <password>your-password</password>
    <nonProxyHosts>localhost|127.0.0.1|*.yourcompany.com</nonProxyHosts>
  </proxy>

  <!-- HTTPS Proxy Configuration (often required separately) -->
  <proxy>
    <id>company-https-proxy</id>
    <active>true</active>
    <protocol>https</protocol>
    <host>your-proxy-server</host>
    <port>your-proxy-port</port>
    <username>your-domain\your-username</username>
    <password>your-password</password>
    <nonProxyHosts>localhost|127.0.0.1|*.yourcompany.com</nonProxyHosts>
  </proxy>
</proxies>
  • Key checks:
    • Ensure <active> is set to true for the proxies you want to use.
    • If your company uses a domain account, include it in the username (e.g., CORP\john.doe).
    • Escape special characters in your password (e.g., replace @ with %40, & with %26).
    • Verify nonProxyHosts doesn't accidentally include Maven repository hosts.

2. Confirm Maven is Using the Right settings.xml

It’s easy to edit the wrong settings.xml file! Maven pulls configuration from two possible locations:

  • User-level: ~/.m2/settings.xml (Linux/macOS) or C:\Users\[YourName]\.m2\settings.xml (Windows)
  • Global-level: [Maven-Install-Dir]/conf/settings.xml

Run this command to see which settings are actually active:

mvn help:effective-settings

Look for the <proxies> section in the output—if your configuration isn’t there, you modified the wrong file.

3. Handle NTLM Proxy Authentication (Super Common for Corporate Networks)

Most company proxies use NTLM authentication, which browsers handle automatically with your Windows login, but Maven doesn’t. Add the <auth> tag to your proxy config to specify NTLM:

<proxy>
  <id>company-ntlm-proxy</id>
  <active>true</active>
  <protocol>http</protocol>
  <host>proxy.corp.com</host>
  <port>8080</port>
  <username>CORP\jane.smith</username>
  <password>your-pass</password>
  <auth>NTLM</auth> <!-- This line is critical for NTLM -->
  <nonProxyHosts>localhost|*.corp.com</nonProxyHosts>
</proxy>

4. Test Proxy Connectivity Outside Maven

Rule out proxy server issues by testing with a tool like curl:

# Test HTTPS access to Maven Central via your proxy
curl -x http://your-domain\your-username:your-password@proxy-host:port https://repo.maven.apache.org/maven2

If this command fails, the problem lies with the proxy itself (reach out to your IT team). If it works, the issue is definitely in Maven’s configuration.

5. Check for Security Software Blocking Maven

Sometimes corporate firewalls or endpoint protection tools block Java applications like Maven, even if browsers are allowed. Try:

  • Running your terminal/IDE as an administrator.
  • Checking your security software’s logs to see if Maven is being blocked.
  • Temporarily disabling the software (if permitted) to test connectivity.

内容的提问来源于stack exchange,提问作者Ashwini

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:33:37