Programing

프록시를 통해 Maven을 어떻게 사용합니까?

crosscheck 2020. 7. 19. 10:23

프록시를 통해 Maven을 어떻게 사용합니까?


프록시를 통해 maven을 사용한 경험을 공유하고 싶습니다.

다음과 같은 예외 및 메시지가 발생할 가능성이 높습니다.

'org.apache.maven.plugins'에 대한 저장소 메타 데이터를 검색 할 수 없습니다. 
저장소 : 오류로 인한 중앙 : 파일 전송 오류 : 연결 거부 : 연결

또는

[경고] org.apache.maven.plugins : maven-clean-에 대한 플러그인 설명자를 검색하지 못했습니다.
플러그인 : 2.5 : 플러그인 org.apache.maven.plugins : maven-clean-plugin : 2.5 또는 그 중 하나 
종속성을 해결할 수 없습니다.에 대한 아티팩트 설명자를 읽지 못했습니다. 
org.apache.maven.plugins : maven-clean-plugin : jar : 2.5

프록시 서버를 사용하도록 Maven을 구성하는 방법은 무엇입니까?


Maven 프록시 설정에 대한 자세한 내용은 미니 안내서를 참조하십시오 .

기본적으로 전역 설정 ( [maven install]/conf/settings.xml) 또는 사용자 설정 ( ${user.home}/.m2/settings.xml) 의 프록시 섹션 이 올바르게 구성되어 있는지 확인해야 합니다. 암호는 일반 위치에 일반 텍스트로 저장하지 않으려면 사용자 설정에서이 작업을 수행하는 것이 좋습니다.

Maven 2.1은 비밀번호 암호화를 도입 했지만 암호화가 프록시 설정 및 저장소 비밀번호에 적용되는지 여부를 확인하는 데 어려움을 겪지 않았습니다 (그렇지 않은 이유는 모르겠습니다).

자세한 내용은 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>

양말 프록시를 사용하는 방법?

어딘가에 서버에 SSH 터널을 설정하십시오.

ssh -D $PORT $USER@$SERVER

리눅스 (bash) :

export MAVEN_OPTS="-DsocksProxyHost=127.0.0.1 -DsocksProxyPort=$PORT"

윈도우 :

set MAVEN_OPTS="-DsocksProxyHost=127.0.0.1 -DsocksProxyPort=$PORT"

또한 일부 플러그인 (원격 리소스를 염두에두고)은 MAVEN_OPTS를 통한 프록시 구성 만 허용하는 오래된 라이브러리를 사용합니다.

-Dhttp.proxyHost=<host> -Dhttp.proxyPort=<port> -Dhttps.proxyHost=<host> -Dhttps.proxyPort=<port>

이 인증에 붙어있을 수 있습니다.


또한이 문제가 있었고 .m2 폴더의 settings.xml 파일을 편집하여 문제를 해결했습니다. 내 settings.xml은 다음과 같습니다 :

<settings>
  <proxies>
    <proxy>
      <id>genproxy</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>proxyHost</host>
      <port>3128</port>
      <username>username</username>
      <password>password</password>
    </proxy>
 </proxies>
</settings>

설정하려면 메이븐 프록시 :

~ / .m2 / settings.xml 파일 에서 프록시 세션을 편집 하십시오 . 파일을 찾을 수 없으면 파일을 작성하십시오.

<settings>
<proxies>
    <proxy>
        <id>httpproxy</id>
        <active>true</active>
        <protocol>http</protocol>
        <host>your-proxy-host</host>
        <port>your-proxy-port</port>
        <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
<proxy>
        <id>httpsproxy</id>
        <active>true</active>
        <protocol>https</protocol>
        <host>your-proxy-host</host>
        <port>your-proxy-port</port>
        <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>

</proxies>
</settings>

또는

{M2_HOME} /conf/settings.xml 에서 프록시 세션을 편집하십시오.

그것이 도움이되기를 바랍니다 .. :)


이러한 문제는 두 가지 문제로 인해 발생할 수 있습니다.

  1. You need to add proxy configuration to your settings.xml. Here's a trick in your username field. Make sure it looks like domain\username. Setting domain there and putting this exact slash is important '\'. You might want to use <![CDATA[]]> tag if your password contains non xml-friendly characters.
  2. I've noticed maven 2.2.0 does not work sometimes through a proxy at all, where 2.2.1 works perfectly fine.

If some of those are omitted - maven could fail with random error messages.

Just hope I've saved somebody from googling around this issue for 6 hours, like I did.


Just to add my own experiences with this: my company's proxy is http://webproxy.intra.companyname.com:3128. For maven to work via this proxy, the settings have to be exactly like this

<settings>
  <proxies>
    <proxy>
      <id>default</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>webproxy.intra.companyname.com</host>
      <port>3128</port>
    </proxy>
  </proxies>
</settings>

Unlike some other proxy-configuration files, the protocol here describes how to connect to the proxy server, not which kinds of protocol should be proxied. The http part of the target has to be split off from the hostname, else it won't work.


Thanks @krosenvold.

If the settings file changes don't work, try this in the command prompt having the POM file.

mvn install -Dhttp.proxyHost=abcproxy -Dhttp.proxyPort=8080 -Dhttps.proxyHost=abcproxy -Dhttps.proxyPort=8080

This has helped me immediately after a password change.


I run cntlm localy, configured with NTLMv2 password hashes to authenticate with the corporate proxy, and use

export MAVEN_OPTS="-DproxyHost=127.0.0.1 -DproxyPort=3128"

to use that proxy from maven. Of course the proxy you use should support cntlm/NTLMv2.


And to add to this topic, here're my experiences below... Really odd and time consuming so I thought it was worth adding.

I've had a similar problem trying to built the portlet-bridge on Windows, getting the following errors:

Downloading: http://repo1.maven.org/maven2/org/apache/portals/bridges-pom/1.0/bridges-pom-1.0.pom
[DEBUG] Reading resolution tracking file C:\Documents and Settings\myuser\.m2\repository\org\apache\portals\bridges-pom\1.0\bridges-pom-1.0.pom.lastUpdated
[DEBUG] Writing resolution tracking file C:\Documents and Settings\myuser\.m2\repository\org\apache\portals\bridges-pom\1.0\bridges-pom-1.0.pom.lastUpdated
[ERROR] The build could not read 1 project -> [Help 1]
org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM: Could not transfer artifact
org.apache.portals:bridges-pom:pom:1.0 from/to central (http://repo1.maven.org/maven2): Error transferring file: repo1.maven.org and 'parent.relativePath' points at wrong local
POM @ line 23, column 11
...
[ERROR]   The project org.apache.portals.bridges:portals-bridges-common:2.0 (H:\path_to_project\portals-bridges-common-2.0\pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM: Could not transfer artifact org.apache.portals:bridges-pom:pom:1.0 from/to central (http://repo1.maven.org/maven2):
Error transferring file: repo1.maven.org and 'parent.relativePath' points at wrong local POM @ line 23, column 11: Unknown host repo1.maven.org -> [Help 2]
...
[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/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException

I tried a couple of things, following a bit of surfing:

  • Tried to set the parent.relativePath as empty so that maven didn't think the parent was local. This is as per the suggestion on SO at Hudson build fail: Non-resolvable parent POM and in this nabble forum. This had no effect.

  • I also tried ensuring the repository was explicitly listed in my settings.xml but this had no effect either.

  • I then ensured mvn was forced to lookup the repository, rather than rely on it's own history, as discussed in this blog by Sarthon. Unfortunately, this wasn't the issue either.

  • In some desperation, I then revisited my MAVEN_OPTS to ensure I wasn't falling foul of my proxy settings. These were correct, albeit with the value unquoted:

    set MAVEN_OPTS= -Dhttp.proxyHost=myproxy.mycompany.com -Dhttp.proxyPort=8080 -Xmx256m

  • So, finally, I moved the proxy config into my settings.xml and this worked:

    <proxies>
      <proxy>
        <id>genproxy</id>
        <active>true</active>
        <protocol>http</protocol>
        <!--username>proxyuser</username-->
        <!--password>proxypass</password-->
        <host>myproxy.mycompany.com</host>
        <port>8080</port>
        <nonProxyHosts>*.mycompany.com|127.0.0.1</nonProxyHosts>
      </proxy>
    </proxies>

Really not sure why my original MAVEN_OPTS wasn't working (quotes?) while the settings.xml config did work. I'd like to reverse the fix and check each step again but have wasted too much time. Will report back as and when.


I know this is not really an answer to the question, but it might be worth knowing for someone searching this post. It is also possible to install a Maven repository proxy like nexus.

Your maven would be configured to contact the local Nexus proxy, and Nexus would then retrieve (and cache) the artifacts. It can be configured through a web interface and has support for (http) proxies).

This can be an advantage, especially in a company setting, as artefacts are locally available and can be downloaded fast, and you are not that dependent on the availability of external Maven repositories anymore.

To link back to the question; with Nexus there is a nice GUI for the proxy configuration, and it needs to be done on one place only, and not for every developer.


If maven works through proxy but not some of the plugins it is invoking, try setting JAVA_TOOL_OPTIONS as well with -Dhttp*.proxy* settings.

If you have already JAVA_OPTS just do

export JAVA_TOOL_OPTIONS=$JAVA_OPTS

if you are new to proxy setup for Maven In my case first go and check your Home Folder weather there is .m2 folder and in it there should be a file named settings.xml if not create it , and paste this and change host and port,then if needed change the nonProxyHosts

Home Folder - C:\Users\ {UserName}

<settings>
<proxies>
    <proxy>
        <id>httpproxy</id>
        <active>true</active>
        <protocol>http</protocol>
        <host>your-proxy-host</host>
        <port>your-proxy-port</port>
        <nonProxyHosts>localhost</nonProxyHosts>
    </proxy>
<proxy>
        <id>httpsproxy</id>
        <active>true</active>
        <protocol>https</protocol>
        <host>your-proxy-host</host>
        <port>your-proxy-port</port>
        <nonProxyHosts>localhost</nonProxyHosts>
    </proxy>

</proxies>
</settings>

If any case this does not success go and do the changes in this location of Home Folder

/conf/settings.xml

I am using Eclipse as my IDE
Hope this will help !!


Except for techniques mentioned above, with some effort, you can run maven through proxy using jproxyloader library (there is example on page how to do this: http://jproxyloader.sourceforge.net/). This allows set up socks proxy only for downloading artifacts.

In solution mentioned by duanni (setting -DsocksProxyHost) there is one problem. If you have integration tests running against local database (or another tests connecting to url which should not go via proxy). These tests will stop working because connections to database will also be directed to proxy. With help of jProxyLoader you can set up proxy only for nexus host. Additionally if you want you can pass connections to database through another proxy.


Some times you need to add other <proxy></proxy> tags, and specify the https in the protocol tags: <protocol>https</protocol>


The above postings helped in resolving my problem. In addition to the above I had to make the following changes to make it work :

  • Modified Maven's JRE net settings(\jre\lib\net.properties) to use system proxy setting.

    https.proxyHost=proxy DNS
    https.proxyPort=proxy port
    
  • Included proxy server settings in settings.xml. I did not provide username and password settings as to use NTLM authentication.

참고URL : https://stackoverflow.com/questions/1251192/how-do-i-use-maven-through-a-proxy