Joshua Fox
Joshua Fox

Reputation: 19655

How can I make Intellj use my environment variables?

My PATH and JAVA_HOME are defined in ~/.bashrc.

However, when I launch Intellij from my Favorite icon and then launch a Maven Run Configuration, these variables are not thus defined. But if directly I run the same idea.sh script that is run from the Favorites icon, then they are recognized.

My pom.xml does some exec, so having these environment variables is essential.

The setting for "Include System Environment Variables" is checked. (As a test, I previously defined env variable FOOBAR-- we see it is missing here.) env vars.

How can I make this happen automatically, even when I use the Favorites icon? The desktop file is given below.

[Desktop Entry]
Version=1.0
Type=Application
Name=IntelliJ IDEA Ultimate Edition
Icon=/hdd/executables/idea-IU-191.6707.61/bin/idea.svg
Exec="/hdd/executables/idea-IU-191.6707.61/bin/idea.sh" %f
Comment=Capable and Ergonomic IDE for JVM
Categories=Development;IDE;
Terminal=false
StartupWMClass=jetbrains-idea

Upvotes: 12

Views: 19044

Answers (4)

Reto
Reto

Reputation: 76

Had a very similar issue and found this post. It helped me but the following information was missing:

Restart: When creating a new environment variable, you have to close/reopen IntelliJ so the new variable is available.

Command Line: When you want to use it on the maven command line, you can do something like:

 mvn clean install -DyourVariableName=${YOUR_ENV_VARIABLE}

Upvotes: 1

Özgün
Özgün

Reputation: 432

In case your env variables are comming from a seperate key management tool like Hashicorp Vault, there is a maven plugin that allows fetchin your secrets and making them available in your maven build.

Like so you don't have to duplicate their declaration in intellij.

Please see my answere here

Upvotes: 0

Lesiak
Lesiak

Reputation: 25976

  • Go to Build, Execution and Deployment -> Build Tools -> Maven -> Runner -> Environment
  • Find a little icon on the right edge of Environment Variables text box.
  • On a pop-up widnow, check Include System Environment Variables

Upvotes: 17

Dilan Tharaka
Dilan Tharaka

Reputation: 567

First click on marked button on configuration window, enter image description here

then, check 'Include system variables' check box enter image description here

Upvotes: 3

Related Questions