Corporate networks love proxies.  Homes usually not.  A little known secret in developer lives is that some of us sneak out of bed late at night to fix that lonely bug that has been teasing us through the day at work.  You fix it, fire up the build and dang! suddenly maven crapped on you telling it cannot reach some url.  Welcome to the proxy hell.

You know the problem.  Your ~/.m2/settings.xml has a proxy configured to access everything your build wants.  Only fly in the ointment is that your proxy is at the office.  Here at home you are a free man.  But unfortunately there is no nice way to let maven know it.  Well, that was till now.

Java has a nice way of solving this problem for you by using a JVM switch.  All you need to do is to add

   1: mvn clean install

to maven command.  Now suddenly maven knows that you do not want to use any proxies.  In fact you can safely get rid off the <proxy> tag from your settings.xml.  What this switch does is to to tell JRE that you would like to use system level proxy settings. This works in windows and in GNOME.  If you use different sets of proxies for development resources vs. normal browsing then this might not work for you.

Another application of this switch is that now you can easily make your java applications use System proxy settings.

   1: System.setProperty(",true);

By adding this to an appropriate initialization routine will ensure that your program will use whatever proxy configuration is specified at the system level will be used.  This is much better that providing ugly property sets to specify redundant information you already have put in elsewhere.

Interestingly setting to MAVEN_OPTS did not help.  It would have been very handy had it.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Post Navigation