Within java, I am trying to access two environment variables that I previously set on my Mac computer (running Yosemite). I have set values for two variables: JAVA\_HOME and R\_HOME. When setting R\_HOME, I did it by editing: ~/Library/launchagents/environment.plist.

Using Terminal on the mac, I can use the 'printenv' command and get values for both variables.

When I run my java application within Eclipse, I can get the JAVA\_HOME value by using: 

```
System.out.println("javahome: " + System.getProperty("java.home") );

```

I have used the following code to list environment variables available to my java application (the list of available values that this code outputs includes neither JAVA\_HOME nor R\_HOME):

```
Map<String, String> env = System.getenv();
for (String envName : env.keySet()) {
    System.out.format("%s=%s%n", envName, env.get(envName));
}

```

My application will need to be standalone, so setting environment variables within the Eclipse Run configuration won't be helpful. Furthermore, my application won't know the value of R\_HOME when it runs; the value must already be set so the application can access it at runtime and use the value to start an executable file, as in:

```
ProcessBuilder pb = new ProcessBuilder("$R_HOME/library/Rserve/libs/Rserve");
Process p = pb.start();

```

So, my question is: how can my java application access the value of the R\_HOME environment variable. Either I need a new way to setting the variable so that it is available to the JVM or I need a new java method to call to access the value.