The reason you need to put export in your .bash_profile is because the environment variables in the shell save only the variables in that shell and - since you used export - for the children of this shell, or, in other words, other programs running this shell.
If you run Java code from Eclipse and run Eclipse from a shell with the environment variables you set, your program should see additional environment variables. To start Eclipse from the shell, you need the OS X open command:
$ open /Applications/eclipse/Eclipse.app
Alternatively, you can set environment variables in an Eclipse project, and you will need to do this if you are not running Eclipse from a shell with the proper environment. In the Run Configurations dialog box, find the Environment tab. Here you will find a table for adding environment variables that will be passed to your program.
Itβs better to add environment variables to your startup configuration, as they will always be available for your project. Your code doesnβt really care where the environment variables come from, and adding them to the project is simpler and will work the same on different platforms.
Of course, when you run your program outside of Eclipse, you need to make sure that the same environment variables exist in the shell where you, for example. execute java .
source share