The proxy settings you set within Eclipse will affect all tools including Eclipse and Maven itself. This might be the reason why you had a 'hang' ... it might not have been your JUnit test, but maven itself hanging (need clarification).
However, in this case, it appears to me that you can change the System Properties from within the plugin responsible for JUnit tests:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<systemPropertyVariables>
<java.net.useSystemProxies>true</java.net.useSystemProxies>
</systemPropertyVariables>
</configuration>
</plugin>
[UPDATE]
In some cases the System Property is only used at startup, and only works when you set it at the command-line. In that case, you can supply it as part of the command-line arguments:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<argLine>-Djava.net.useSystemProxies=true</argLine>
</configuration>
</plugin>
Also note that if you want to run it from within maven, you have to choose 'Run as -> Maven test', and not 'Run As -> JUnit Test'.
[RANTING Follows]
I hate to say this - but at this point the support for Proxies is really poor within Java.
One major improvement has ever been made: now you can define a separate Proxy for each connection you want to establish. However, I think this should be improved by a lot:
- Separate authentication per proxy. Now even though I can define proxy per connection, it is just unnatural to use the same authentication for all. Worse, it even triggers the same authentication for both proxy and HTTP connection: it is not able to distinguish these two even.
- Better support for SOCKS proxies
- Better support to query the system for proxy setup. Every modern OS now has a configuration for default proxy.
- Built-in support and API's for actual Socket Servers.
Sounds like the rants of a disillusioned programmer, but the answer is in the implementation of these! Is this worthy a JEP?
mvn -X
provide some more information? What tests do you run in yourMyTestClass
. – FlorinaprintSystemProxy
. I tried again in a clean project, and maven returns, but still eclipse hangs with Junit if system property is defined. – KephartBlockJUnit4ClassRunner
constructor (as seen bydebugging
) – Kephart