Created
November 17, 2014 16:03
-
-
Save prietopa/eb4ed667013adc981fb1 to your computer and use it in GitHub Desktop.
add proxy(user-pass) to java execution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void addProxy(String user, String pass, String host, String port) { | |
if(user!= null && pass != null) { | |
final String authUser = user; | |
final String authPassword = pass; | |
Authenticator.setDefault( | |
new Authenticator() { | |
public PasswordAuthentication getPasswordAuthentication() { | |
return new PasswordAuthentication( | |
authUser, authPassword.toCharArray()); | |
} | |
} | |
); | |
System.setProperty("http.proxyUser", authUser); | |
System.setProperty("http.proxyPassword", authPassword); | |
} | |
System.setProperty("http.proxyHost", host); | |
System.setProperty("http.proxyPort", port); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment