I have created an environment variable on my mac called "api_url". I want Java to read that variable and store it as a string.
Why doesn't the code below work? Notice at the bottom, the output is "null".
I have created an environment variable on my mac called "api_url". I want Java to read that variable and store it as a string.
Why doesn't the code below work? Notice at the bottom, the output is "null".
You misunderstood something here. Properties are information about the local system and configuration. To access environment variables, you have to use System.getenv()
instead of System.getProperty()
.
Try String url = System.getenv("api_url");
.
You're using System.getProperty
, which is for getting JVM properties - not environment variables. You need to use System.getenv("api_url")
instead.