0

I am using MacOs Catalina 10.15.7. I add an env variable "LOG_PATH" in .bash_profile. After that, I restart computer and run printenv. I can see that variable. So far so good.

I have a java code to get the value from that env variable:

 System.out.println("LOG PATH="+System.getenv("LOG_PATH"));

But it returns null. How does that happen?

David
  • 3,538
  • 9
  • 39
  • 50
  • How do you run your Java program? You'd have to start it from a bash prompt to get any bash variables. – Robert Sep 15 '21 at 19:21
  • 1
    See if the first answer [here](https://stackoverflow.com/questions/65597552/how-exactly-to-set-up-and-use-environment-variables-on-mac) works for you. – Alias Cartellano Sep 15 '21 at 19:27
  • I am running java code from eclipse IDE – David Sep 15 '21 at 19:27
  • 1
    @David: and which one of the parent processes of the Eclipse IDE do you expect to interpret `.bash_profile`? If there's no bash anywhere in there, then that file means nothing. Read the question Alias Cartellano linked to, it has a detailed explanation of which files influence what. – Joachim Sauer Sep 15 '21 at 19:28
  • @Joachim: I install Eclipse in macos and click on the icon to run Eclipse IDE. I dont know what is the parent process of Eclipse IDE. The .bash_profile that i modified is the one stays in /Users/david1234. (david1234 is my username). The link from Alias is for BigSur not Catalina. – David Sep 15 '21 at 19:38
  • https://stackoverflow.com/questions/6669821/how-to-use-environment-variables-in-java-with-eclipse-mac-os-x/6669853#6669853. Try this one instead. – Alias Cartellano Sep 15 '21 at 19:41

0 Answers0