Environment variables set in debug configuration not passed to environment

I've searched to see if there are any reports similar to this and there aren't, at least not that I can find. So apologies if this is answered somewhere else, but I can't dig it up if it is!

I have a bit of code where I'm checking the values of various environment variables to determine the home folder for our application (where data and configurations will be stored, mainly). The order of precedence for these settings is:

  • The Java system property xnat.config.home
  • The environment variable XNAT_HOME
  • The environment variable HOME

HOME is already set in the server environment, so I set the other two variables in the debug configuration (where the application is running as a web app within Tomcat 7). The first as a VM option:

Screen Shot 2015-10-15 at 10.26.07 AM.png
The second as a an environment variable on the startup/connection tab:

Screen Shot 2015-10-14 at 3.13.26 PM.png
Interesting! My VM option got converted to a JAVA_OPTS environment variable. That's important, as you'll see in a second.

I run my app using this configuration. When I get into the code, I can get the value for xnat.config.home with no problem:

Screen Shot 2015-10-14 at 3.12.39 PM.png
So the JAVA_OPTS value is getting passed along OK. The HOME environment variable also resolves:
Screen Shot 2015-10-14 at 3.12.53 PM.png
XNAT_HOME does not:
Screen Shot 2015-10-14 at 3.13.07 PM.png
In practice, this won't be a problem: XNAT_HOME will be set in the environment in pretty much the same way that the HOME value is set, so it will get picked up in the same way. But it does make testing this in development difficult. I'm reasonably certain that the problem is that the Tomcat process is being forked and connected, so that the forked process isn't operating in the same environment space, but that would make any environment configuration prior to the fork completely useless.

Is there some magic I need to do to get my environment variables available to applications within a server container?

This is with IntelliJ IDEA 14.1.5 on OS X 10.10.5.

Thanks for any help!
1 comment
Comment actions Permalink

Try printing environment variables from the startup.sh (inside Tomcat bin folder) to see if they are passed by IDEA. Just echo them and observe the result in IDEA Run console after starting the server.

If you can see that the variables are available in startup.sh, you may need to adjust this script so that it also passes these variables to the JVM that it executes.

0

Please sign in to leave a comment.