vagrant-proxyconf icon indicating copy to clipboard operation
vagrant-proxyconf copied to clipboard

Support JVM proxy settings for Java

Open gtback opened this issue 10 years ago • 7 comments

It would be great if vagrant-proxyconf could support the http.proxyHost, http.proxyPort, and http.nonProxyHosts (along with HTTPS and FTP) options to the JVM.

Ref: http://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html

I'm not sure the best way to set these (via environment variables such as JAVA_OPTS, perhaps?), or if they need to be explicitly passed to JVM invocations. I'm not that experienced with either Ruby or Java, but I'm happy to help out any way I can.

Background: I'm trying to install ElasticSearch plugins using Ansible (on machines both behind a proxy and not). While I could (and probably will in the short term) manually tweak the command-line invocation of the plugin command for proxy environments, it would be great if this was handled transparently by vagrant-proxyconf, which I'm using for other proxy-related settings on this project.

gtback avatar May 20 '15 14:05 gtback

I'm afraid that this is impossible to do in a generic way. It totally depends how you invoke the JVM. While many scripts honor JAVA_OPTS or something like it, they also set/override it in their configuration file. It's really pity java doesn't support the standard environment variables here.

So I believe you have to set the JVM parameters via your own provisioner when you configure the application itself. If someone has more insight, please comment and we'll reopen the issue.

tmatilai avatar Jul 26 '15 08:07 tmatilai

Thanks, @tmatilai. It's unfortunate that there's not a good way to do this in Java; not the fault of vagrant-proxyconf though. :smiley:

gtback avatar Jul 29 '15 16:07 gtback

@gtback just stumbled over elatsicsearch plugin installation behind a corp proxy as well, and finally found my way here.

So there is one thing that seems to work generically, namely the _JAVA_OPTIONS env var: http://stackoverflow.com/a/2966629/2388971

Putting this to /etc/environment (or make sure its otherwise set in the ENV while the provisioner runs) made it work:

_JAVA_OPTIONS='-Dhttp.proxyHost=foo.com -Dhttp.proxyPort=3128 -Dhttps.proxyHost=foo.com -Dhttps.proxyPort=3128'

Thought this would be a useful addition to set in the env via vagrant-proxyconf.

tknerr avatar Jan 21 '16 15:01 tknerr

One more thing: this would probably be something that should always be set as part of configure_env_proxy.rb, instead of detecting for java first.

Why? Because a common use case is to first install java then run a java app (e.g. the elasticsearch plugin command) within a single provisioner run.

tknerr avatar Jan 21 '16 15:01 tknerr

Oh, that's interesting! I have never came across that variable before.

I'll reopen the issue and wait for a pull request. =) Just be sure to append and not replace the original _JAVA_OPTIONS.

tmatilai avatar Jan 21 '16 15:01 tmatilai

We might even want to set

  • _JAVA_OPTIONS for java apps (java.exe)
  • JAVAWS_VM_ARGS for java webstart apps
  • _JPI_VM_OPTIONS for java applets (javaw.exe)

See here: http://stackoverflow.com/a/9677804/2388971

tknerr avatar Jan 21 '16 15:01 tknerr

@tmatilai +1 for appending (or even better: prepending? -- not sure how java deals with that...)

tknerr avatar Jan 21 '16 15:01 tknerr