/etc/profile is read when you login. When the startup scripts are run they have a cut down environment as no user is logged in. I'd set JAVA_HOME in the script itself, but set it to a symlink that gets updated to point to the real location. That way your script won't break every time you upgrade your Java install.
For example, at a shell prompt create the link:
# ln -s /usr/local/jdk1.5.0_07 /usr/local/jdk
In your script:
Hope that helps...