Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run java with properties from environment variable

In my app i need send http requests via proxy. In terminal i start it by this:

java -Dhttp.proxyPort=**** -Dhttp.proxyHost=***.***.***.*** -jar app.jar 

What environment variable i should use for starting on my apps without -D options, like

java -jar app.jar

OS Linux. Java 7.

Thx!

PS already tried JAVA_OPTS, JAVA_OPTIONS, _JAVA_OPTIONS, JAVA_TOOL_OPTIONS...

like image 941
Cuzz Avatar asked Oct 30 '25 04:10

Cuzz


1 Answers

Java has two separate ways to pass parameters to programs:

  • Properties, which are typically specified in the command line arguments (as in your first example), loaded from files or manually added by code.
  • Environment Variables, which are determined by settings in your operating system.

These two concepts are separate; the former doesn't affect the latter and vice versa. As such, you cannot set a property by means of an environment variable.

Other options include loading a .properties file during runtime (assuming your proxy hasn't already been initialized at that point) or putting the full command (-D arguments and all) in a shell script for easier launching.

like image 185
BambooleanLogic Avatar answered Oct 31 '25 18:10

BambooleanLogic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!