Search code examples
tomcatintellij-ideaideenvironment-variablescatalina

IntelliJ Tomcat Run Configuration Does Not Set Environment Variables


I am running Tomcat 8.0.35 on OS X with IntelliJ Ultimate 2016.1.2. I want to run Tomcat locally under the debugger and deploy my web application to it. I created a local Tomcat Server run configuration. In the Deployment tab I specified the WAR file to deploy.

My web application requires REDIS_HOST_MM and REDIS_PORT_MM environment variables to be set. I set these in the Startup/Connection tab of the run configuration.

Startup/Connection Tab of Tomcat run configuration

Tomcat starts and my web application deploys, however, the environment variables are not set. I can put a breakpoint on the following line in my web application's code

String _value = System.getenv(value);

and see that when value equals "REDIS_HOST_MM", the call returns null.

I have the same problem if I set the VM Options in my Server tab to -DREDIS_HOST_MM=127.0.0.1 -DREDIS_PORT_MM=6379. Also if I change the Startup Script to point to the following shell script

export REDIS_HOST_MM=127.0.0.1
export REDIS_PORT_MM=6379
/usr/local/Cellar/tomcat/8.0.35/libexec/bin/catalina.sh run

If I start Tomcat outside IntelliJ from the command line, the environment variables are set correctly.

Is this a bug in IntelliJ, or am I supposed to set the environment variable in some other way?

(This is JetBrains support issue 699091.)


Solution

  • Never mind. User error. I didn't realize you had to set environment variables separately for the Run and Debug configurations. I had them set for Run, but I was running Debug.

    Once I set the environment variables for the Debug configuration too, everything worked.