Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrive environment variable value from code in mac OS

I set an Environment Variable from a .sh file for example

export JBOSS_HOME=/Applications/EAP-6.2.0/jboss-eap-6.2

Now in my Java application if I need to get this JBOSS_HOME I will write

String jbossHome = System.getProperty("JBOSS_HOME");

This works fine when I run the code on the windows machine. It does not give the value for JBOSS_HOME on Mac machine. How can I retrive JBOSS_HOME value on Mac OS machine?

like image 516
Sumit Patel Avatar asked Apr 25 '26 00:04

Sumit Patel


1 Answers

Environments are retrieved via:

System.getenv(name);

Not with System.getProperty().

Use System.getenv() without paramters to get the map of all environment variables.

like image 120
icza Avatar answered Apr 26 '26 12:04

icza



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!