If is that a "real" Proxy the you could specify the proxy to use using java system properties.
You have two alternatives:
- Specify the proxy in the command line
- Hardcode it into your app
Well you actually have three
- Specify a .properties file, and read from there, and set it as System property ( which is pretty much option 2 but more dynamic )
From command line you'll use:
java -Dhttp.proxyHost=localhost -Dhttp.proxyPort=8080 -jar YourJar.jar
With that all the http connections you perform will go through localhost
at port 8080
The second is add this at the main method of your program:
public static void main( String [] args ) {
System.setProperty("http.proxyHost", "localhost");
System.setPropery("http.proxyPort", "8080");
....
}
Which does the same.
Finally loading from myapp.properties
public static void main( String [] args ) {
try { // there are cleaner ways of course
ResorceBundle bundle = ResourceBundle.getBundle("myapp");
System.setProperty("http.proxyHost", bundle.getString("proxy.server"));
System.setPropery("http.proxyPort", bundle.getString("proxy.portr"));
} catch( MissingResourceException mre ){}
....
}
You just have to make sure myapp.properties
is available from the classpath
More information about this functionality here