Skip to content

Instantly share code, notes, and snippets.

@prietopa
Created November 17, 2014 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prietopa/eb4ed667013adc981fb1 to your computer and use it in GitHub Desktop.
Save prietopa/eb4ed667013adc981fb1 to your computer and use it in GitHub Desktop.
add proxy(user-pass) to java execution
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