You likely have not exported the environment variable. In most shells, variables declared in the shell are not exported into the environment of subprocesses unless you do so explicitly, either like this:
export MY_HOME=/somewhere/over/the/rainbow
Or when invoking the program:
MY_HOME=/somewhere/over/the/rainbow java com.example.MyApplication
Also keep in mind that the environment is not global, so changes you make to the environment only affect that process and its subprocesses. If you want to affect the environment of all processes on your system, this has to be configured specially. In most cases, exporting in the shell is what you want.