RSS RSS

Updated: Missing environment variables in IntelliJ IDEA?

By , 2 Jul 2009 12:37 pm

Updated 2010-04-08

I am running IntelliJ IDEA on an Ubuntu 9.04 desktop at work and I’ve had troubles when the IDE attempts to run build scripts, such as Ant or Maven. Typically the scripts would fail with an error message along the lines of “unable to find ${env.APP_HOME}” when looking for a folder whose path was set by my environment variables.

I’ve troubleshot this and found that IDEA isn’t starting with any of my login environment variables when launched from the panel. When I started the IDEAPATH/bin/idea.sh script from the Terminal, everything was peachy. It only failed when I started the application with the gnome-panel or Gnome-Do.

There has been at least one bug filed about this on the IntelliJ bug tracker as best I can determine. People are often caught by this and post regularly in the Jetbrains Community Forumns. Perhaps Google will turn up this post and save a few of them the hassle.

I am also working on another post regarding integrating IntelliJ into a Gnome or KDE desktop, coming shortly.

If you are using Linux:

The fix is quite easy, prepend the shell command with ‘bash --login‘ like so:
bash --login IDEAPATH/bin/idea.sh

Once bash starts as a login shell it will read the correct configuration files and set your environment just as if you had logged in. Simple, right? If you have created a custom desktop entry simply edit it with the menu editors in Gnome or KDE.

If you are using a Mac:

A similar problem can occur, make sure you start IDEA via the application icon, and not using Spotlight, or make sure that Quicksilver has found the real application (.app) and not the startup script (.sh) when you launch it. Personally, I locked Quicksilver to the “correct” version of IDEA, since I also had several installed, and it’s worked well since.

You can add required environment variables to the launchd.conf file, which will make them available to all processes started via Spotlight.

$ sudo vim /etc/launchd.conf

Add the Java environment variables to the file.

setenv JAVA_VERSION 1.6
setenv JAVA_HOME /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
setenv GROOVY_HOME /Applications/Dev/groovy
setenv JRUBY_HOME /Applications/Dev/jruby
setenv ANT_HOME /Applications/Dev/apache-ant
setenv ANT_OPTS -Xmx512M
setenv MAVEN_OPTS -Xmx1024M
setenv M2_HOME /Applications/Dev/apache-maven

Reboot the Mac and test your changes with export or env.

Leave a Reply

You must be logged in to post a comment.

Persephone Theme by Themocracy