0

I have a java application which runs on a linux machine many times at a single login. At the beginning of it, I need to set some environment variables for further use. I did that by appending my variables and their values at the end of both ~/.bashrc and ~/.profile files. In order to make those variables permanent, I should call "source ~/.bashrc" or "source ~/.profile". The problem here is that the source command can not be called through java because of it's scope concerns.

In a single word: How can I set permanent environment variables on my linux machine at the begining of my java application?

HaMi
  • 539
  • 6
  • 23
  • Instead of `java ./myprog`, how about `MYVAR=1 java ./myprog`? Also see [Set Linux environment variable programmatically in Java](https://stackoverflow.com/q/14022487/608639). – jww Jul 08 '17 at 11:56
  • @jww I need to do it inside java, the value of variables calculated at the beginning of my java code – HaMi Jul 08 '17 at 11:58
  • *"the value of variables calculated at the beginning of my java code..."* - Then it sounds like you should use the cited dup. Vamsi Mohan Jayanti answer looks like the one you should use. Ryan Stewart's answer also has some useful information. – jww Jul 08 '17 at 12:03
  • @jww what is that? keep in mind that I will use those environment variables later in other bash scripts – HaMi Jul 08 '17 at 12:05

0 Answers0