What is the proper (2021 way) of creating a permanent environment variable on a mac (Big Sur), and then use it within a java project.
There are many very old posts regarding this topic. none of them seem to work properly nowadays.
- How to add a permanent environment value (through terminal)
- And how can I use it in a java code
(I'm also not sure how I was able to add my testvar=testvalue to the list because I tried so many files [although it seems none of them worked], by adding "export testvar=testvalue" to the following files:
- /etc/paths
- ~/.bashrc
- ~/.bash_profile
- ~/.profile
- /etc/profile
Also after inserting it into each file I used source {file}
So at this point I have no idea which is the proper way to create and have it permanently, and being able to use it in my java code)
So far, I can print the variables into the terminal with
printenv
My variables are getting listed, example:
testvar=testvalue
In my java code, I get null when using:
System.getenv("testvar")
however using an other variable name -that was not created by me, but the macos system- (eg. "USER" ) prints the value as expected.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…