As for every application proxified by jProxyLoader we basically we need to do 3 things: put jproxyloader.jar on classpath of maven, set JProxyLoader as system class loader and drop configuration file to maven's classpath or local filesystem.
This configuration was tested with Maven 3.2.2.
Adding jproxyloader.jar to maven classpath requires two steps to be made. First we put the jar in location where maven can read from. In this location we will place jproxyloader.jar in boot folder of maven installation dir:
C:\Andrzej\tools\apache-maven-3.2.2\boot>dir Directory of C:\Andrzej\tools\apache-maven-3.2.2\boot 2014-08-01 15:44 <DIR> . 2014-08-01 15:44 <DIR> .. 2014-07-31 18:00 33Â 898 jproxyloader-1.0-RC1.jar 2014-07-10 12:33 49Â 793 plexus-classworlds-2.5.1.jar
Now we need to add this jar to classpath of maven. Unfortunately this involves modification of maven startup script. This is because maven builds classpath parameter entirely in maven startup script. There is no way to change it via modification of system CLASSPATH variable because startup script does not take this variable into consideration. Good news is that the modification is really easy. On windows simply go to bin directory of maven and open mvn.bat file in your favourite text editor (on linux you should modify the "mvn" file, see below). Now look for following line:
%MAVEN_JAVA_EXE% %MAVEN_OPTS% -classpath %CLASSWORLDS_JAR% "-Dclassworlds.conf=%M2_HOME%\bin\m2.conf" " -Dmaven.home=%M2_HOME%" %CLASSWORLDS_LAUNCHER% %MAVEN_CMD_LINE_ARGS%
Here maven sets the classpath to %CLASSWORLDS_JAR% (does not matter what that is). We need to simply add jproxyloader.jar to this variable like this:
-classpath %CLASSWORLDS_JAR%;%M2_HOME%\boot\jproxyloader-1.0-RC1.jar
Full modified line is following:
%MAVEN_JAVA_EXE% %MAVEN_OPTS% -classpath %CLASSWORLDS_JAR%;%M2_HOME%\boot\jproxyloader-1.0-RC1.jar "-Dclassworlds.conf=%M2_HOME%\bin\m2.conf" "-Dmaven.home=%M2_HOME%" %CLASSWORLDS_LAUNCHER% %MAVEN_CMD_LINE_ARGS%
On linux you need to modify "mvn" file (not: mvn.bat which is only for windows). In similar way you need to change following fragment:
exec "$JAVACMD" \ $MAVEN_OPTS \ -classpath "${M2_HOME}"/boot/plexus-classworlds-*.jar \ "-Dclassworlds.conf=${M2_HOME}/bin/m2.conf" \ "-Dmaven.home=${M2_HOME}" \ ${CLASSWORLDS_LAUNCHER} "$@"
You need to modify classpath variable in similar way as in windows (beware that on linux you use ":" to separate jars on classpath, not ";" as on windows). NOTE: you need to provide replece the asterisk ("*" character) of plexus-classwords jar with real version as in example below or use alternative version to include all jars from boot (presented below). Your modified mvn script should look like this (please make sure what is the name of plexus-classwords-*.jar in your maven installation, because it may differ):
exec "$JAVACMD" \ $MAVEN_OPTS \ -classpath "${M2_HOME}"/boot/plexus-classworlds-2.5.1.jar:"${M2_HOME}"/boot/jproxyloader-1.0-RC1.jar \ "-Dclassworlds.conf=${M2_HOME}/bin/m2.conf" \ "-Dmaven.home=${M2_HOME}" \ ${CLASSWORLDS_LAUNCHER} "$@"
Alternatively you can include all jar files without stating their version with following modification to mvn file (NOTE: in belows example see where double quotes (") are placed):
exec "$JAVACMD" \ $MAVEN_OPTS \ -classpath "${M2_HOME}/boot/*" \ "-Dclassworlds.conf=${M2_HOME}/bin/m2.conf" \ "-Dmaven.home=${M2_HOME}" \ ${CLASSWORLDS_LAUNCHER} "$@"
Now we need to add maven jvm startup parameter "-Djava.system.class.loader=net.sf.jproxyloader.JProxyLoader". We will use the fact that maven reads system variable MAVEN_OPTS (or M2_OPTS in older releases). It is also worth adding extra parameter -DforkMode=never. This forkMode=never will prevent maven from spawning extra java processes for example when running java tests. Without this parameter extra java processes spawned by maven would lack the "-Djava.system.class.loader=net.sf.jproxyloader.JProxyLoader" parameter. This can be also addressed, for example by configuring JAVA_OPTS to use jProxyLoader, but there is no need to do this if we use -DforkMode=never. Our MAVEN_OPTS variable should be following (of course it can include extra parameters like -Xmx512m -XX:MaxPermSize=320m if you need them):
MAVEN_OPTS=-DforkMode=never -Djava.system.class.loader=net.sf.jproxyloader.JProxyLoader
At this point you can launch new console and type "mvn -v" command. This should print version of maven, but also you should see that jProxyLoader was initialized:
mvn -v Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=320m; support was removed in 8.0 jProxyLoader: Initializing proxy jProxySelector with no proxy hosts: [], custom dns servers: [] and custom proxies config: [] Apache Maven 3.2.2 (45f7c06d68e745d05611f7fd14efb6594181933e; 2014-06-17T15:51:42+02:00) Maven home: C:\Andrzej\tools\apache-maven-3.2.2\bin\.. Java version: 1.8.0_05, vendor: Oracle Corporation Java home: C:\Andrzej\tools\jdk8u5\jre Default locale: en_US, platform encoding: Cp1250 OS name: "windows 7", version: "6.1", arch: "amd64", family: "dos"
You can see the line starting with text "jProxyLoader: Initializing proxy" which means that jProxyLoader was initialized. The last thing to do is to point to configuration file. This can be done in many ways. For example you can create jproxyloader.properties (default files loaded from classpath) in boot dir and add this boot directory to classpath in startup script (remember that in this case configuration will be initialized when first connection is made). In this example we will load configuration from file located on local filesystem by adding extra option to MAVEN_OPTS variable. Suppose that we want our properties file to be located in c:/proxydef directory. We create there a file called jproxies.conf and put some proxies definitions inside. To instruct jProxyLoader to load configuration from this file we will need to add following parameter to MAVEN_OPTS:
-DjplConfigFile=C:/proxydef/jproxies.conf
After the modification MAVEN_OPTS variable should look like this:
MAVEN_OPTS=-DforkMode=never -Djava.system.class.loader=net.sf.jproxyloader.JProxyLoader -DjplConfigFile=C:/proxydef/jproxies.conf
Now when you launch "mvn -v" command you should see that jProxyLoader is using your proxies defined in jproxies.conf file:
mvn -v Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=320m; support was removed in 8.0 jProxyLoader: Initializing proxy jProxySelector with no proxy hosts: [], custom dns servers: [10.0.17.20] and custom proxies config: [[socks@127.0.0.1:7070#[somehost.dmz, apache.org]]] Apache Maven 3.2.2 (45f7c06d68e745d05611f7fd14efb6594181933e; 2014-06-17T15:51:42+02:00) Maven home: C:\Andrzej\tools\apache-maven-3.2.2\bin\.. Java version: 1.8.0_05, vendor: Oracle Corporation Java home: C:\Andrzej\tools\jdk8u5\jre Default locale: en_US, platform encoding: Cp1250 OS name: "windows 7", version: "6.1", arch: "amd64", family: "dos"
What can be benefit of this? Well, you can allow maven to download artifacts via socks proxy, whereas normally maven allows only downloading artifacts through http proxy. Suppose that you defined socks proxy in jproxies.conf file. You can now download artifacts from repositories located behind socks proxy. For example you can have following entry in your settings.xml file:
<mirrors> <mirror> <!-- This sends everything else to /public --> <id>nexus</id> <mirrorOf>*</mirrorOf> <url>http://nexus.behind.proxy.dmz/content/groups/public</url> </mirror> </mirrors>
You can now specify in jproxies.conf file that every call to nexus.behind.proxy.dmz should go through proxy (setting up ip address of nexus.behind.proxy.dmz to go through proxy may also be required). If domain name nexus.behind.proxy.dmz can only be resolved behind of proxy, you can define custom dns server which is located behind proxy (see troubleshooting page) which can resolve nexus.behind.proxy.dmz to its ip address. Now you should be able to download artifacts from repository which is located in another network. I tested this scenario (including setting custom dns for resolving domain name of nexus host) and it worked for me without problems.