How do I set environment variables on OS X?
I have a .profile in my home directory; it contains many export … statements for environment variables.

You can create such a file by opening a Terminal and issuing the command touch .profile
Close Terminal. 

Then you should open that file in a plain-text editor (TextWrangler for example). You can also use nano .profile in a Terminal window (current directory should be your home), which is much easier than vi. Insert lines such as export JAVA_HOME=… . Save, exit nano if you used that and quit a running Terminal.

Open Terminal and issue the command env to see all environment variables. Check that the ones you defined have the value you assigned to them. You should be good to go now. But don't forget that environment variables defined in .profile are not passed to GUI applications.