Lion Eats Ant, or Giving Lion Java GUI Programs Access to Environment Variables (Phew)

Upgrading an OS is always fun, especially when you go for a clean install and forget about the 40 million really useful applications you need to make your life comfortable. Then you run into all the subtle changes that break the way you did things beforeā€¦

I ran into one of those with FDT 4.5 on Lion recently. Suddenly, my FDT Ant build scripts no longer picked up my FLEX_HOME environment variable. After much wailing and gnashing of teeth, it turns out that simply exporting a variable from your .bash_profile isn’t enough for some GUI applications. I’m not certain why yet, but FDT (or Java) is now launched by a service called launchd (man, wiki). To make environment variables available to processes opened by launchd, you must set them using launchctl setenv VAR $VALUE.

So, for example, the relevant part of my .bash_profile looks like this:

Add that to your .bash_profile, or type it into a terminal to test it, relaunch FDT and it should all work. If you want to check what variables are available in your ant file, don’t forget that you can add an <echoproperties/> tag to dump them to stdout.