Setting up and using environment variables in IntelliJ Idea

Intellij IdeaEnvironment Variables

Intellij Idea Problem Overview


I set up an environment variable (Under IDE Settings -> Path Variables)

 APP_HOME = /path/to/app_home  

One of my tests is failing however with

 System.out.println("APP HOME: " + APP_HOME); 

With

 APP HOME: null/ 

It does not look like that env variable is being read. What am i missing?

Intellij Idea Solutions


Solution 1 - Intellij Idea

Path Variables dialog has nothing to do with the environment variables.

Environment variables can be specified in your OS or customized in the Run configuration:

env

Solution 2 - Intellij Idea

If the above answer + restarting the IDE didn't do, try restarting "Jetbrains Toolbox" if you use it, this did it for me

Solution 3 - Intellij Idea

It is possible to reference an intellij 'Path Variable' in an intellij 'Run Configuration'.

In 'Path Variables' create a variable for example ANALYTICS_VERSION.

In a 'Run Configuration' under 'Environment Variables' add for example the following:

ANALYTICS_LOAD_LOCATION=$MAVEN_REPOSITORY$\com\my\company\analytics\$ANALYTICS_VERSION$\bin

To answer the original question you would need to add an APP_HOME environment variable to your run configuration which references the path variable:

APP_HOME=$APP_HOME$

Solution 4 - Intellij Idea

I could not get environment variables to work when IntelliJ Build and run property was using Gradle. I am not sure what the root cause is, but switching to IntelliJ IDEA solved the problem. Go to Preferences -> Build, Execution, Deployment -> Build Tools -> Gradle. Then change Build and run using: to IntelliJ IDEA.

IntelliJ Run Preferences

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJames LeonardView Question on Stackoverflow
Solution 1 - Intellij IdeaCrazyCoderView Answer on Stackoverflow
Solution 2 - Intellij IdeasamView Answer on Stackoverflow
Solution 3 - Intellij IdeaCrumpView Answer on Stackoverflow
Solution 4 - Intellij IdeaFreddieView Answer on Stackoverflow