How do I specify a http proxy to use when running a spring-boot fat war as a tomcat server?
I have tried the following which is not working.
java -ja
Put the JVM options before -jar
. This should work:
java -Dhttp.proxyHost=localhost -Dhttp.proxyPort=3128 -Dhttps.proxyHost=localhost -Dhttps.proxyPort=3128 -jar my-application.war
Explanation
According to java command-line documentation, the command's syntax is:
java [ options ] -jar file.jar [ arguments ]
The arguments
are the args
that'll be received in your main(String[] args)
. So, it's totally your responsibility to use them somehow. And if you forward them to spring using SpringApplication.run(MyApplication.class, args);
, then you need to find documentation that says how spring uses args
in the run
method.
The options
, however, are not sent to your app. One of their uses is to set what java calls system properties
using -Dproperty=value
. According to Java Networking and Proxies, setting, e.g., http.proxyHost
property makes the JVM proxy all your http request through that host.