Posted by Ekesh Bahuguna | Last Updated: 29-Jun-18
Need: Properties file may contain sensitive information like password, emailed etc. If such information is defined in the properties file, anyone who has access to our code can know server location, email, password etc.
Set the properties variable
file as follows: (such as values of property variables will not visible directly, rather saved in
bashrcand retrieved from the same).
2- export the variables that need to be set into
3- Save the file
4- Reflect the changes done in
5- Check from terminal whether
variableis set to bashrcor not
if [ -z "$MAIL_HOST" ]
echo "not defined"
If MAIL_HOST is properly set to
bashrcthen the output will be defined else not defined or in another case respective mail host will be printed.
6- Access the configuration set into
bashrcto properties file:
Benefits of approach:
When we set the information
in bashrcwe do not require to set multiple profiles. Since different profile may use different configuration hence we can simply set the properties required for development in development bashrc, production in production's bashrcand so on..
This approach reduces the code for setting multiple profiles. Moreover, this is a secure way to access sensitive information. Now if anyone has access to our code is not eligible to access our security details such as email and password.
Note: To reflect the changes done in
bashrcsometime one may require to source the bashrcfrom the project location. So before running the application, it is required to source the bashrcfrom project location as follows: