BitterSweetJaVa

November 27, 2009

Proxy setup in Java / Maven / SVN project

Filed under: Java, Maven, S.C.M. — Tags: , , , , , — .|2ic|K @ 11:59 AM

To setup a proxy to be used by Maven only, you need to have it defined in the settings.xml file.
This file is located in [USR_HOME]\.m2 directory (C:\Documents and Settings\[USERNAME]\.m2 for Windows users).
Here’s an example of the file:


<settings>
  <proxies>
   <proxy>
      <active>true</active>
      <protocol>http</protocol>
      <host>[PROXY SERVER]</host>
      <port>[PROXY PORT]</port>
      <username>[PROXY USERNAME]</username>
      <password>[PROXY PASSWORD]</password>
      <nonProxyHosts>www.website1.com|*.website2.com</nonProxyHosts>
    </proxy>
  </proxies>
</settings>

To setup a proxy to be used for a Java application:


System.getProperties().put("http.proxyHost", [PROXY SERVER]);
System.getProperties().put("http.proxyPort", [PROXY PORT]);
System.getProperties().put("http.proxyUser", [PROXY USERNAME]);
System.getProperties().put("http.proxyPassword", [PROXY PASSWORD]);

To display the proxy server used for a particular URL:

URL url = new URL("http://www.treasurydirect.gov/xml/CPI_20090814.xml");
System.out.println(ProxySelector.getDefault().select(url.toURI()));

Update Dec. 7, 2009: Proxy setup for Subversion command line and subclipse plugin (eclipse).

You should have a file named ‘servers‘ under C:\Documents and Settings\[USR_HOME]\Application Data\Subversion.
The file has pretty good inline documentation.
In my case, at the end of the file, I modified the following lines under [global] group:

[global]
http-proxy-host = [PROXY SERVER]
http-proxy-port = [PROXY PORT]
#http-proxy-username = [PROXY USERNAME]
#http-proxy-password = [PROXY PASSWORD]
http-compression = no
http-auth-types = basic;digest;negotiate

Advertisement

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Theme: Shocking Blue Green. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.