First, ensure your application is in Solaris's SMF. Here is an example for a Tomcat application server. The same steps will work for Glassfish and other Java applications.
Get the FMRI name. The string that starts with "svc".
root@rule:/# svcs -av |grep tomcat6 online - 6:00:59 775330 svc:/network/http:tomcat6-csk root@rule:/#
Now set the JAVA_HOME and refresh the SMF service.
root@rule:/# svccfg -s svc:/network/http:tomcat6-csk setenv -m stop JAVA_HOME /usr/jdk/latest root@rule:/# svccfg -s svc:/network/http:tomcat6-csk setenv -m start JAVA_HOME /usr/jdk/latest root@rule:/# svcadm refresh svc:/network/http:tomcat6-csk root@rule:/#
That should do it. You can then do ps -ef |grep java to check that you are using the latest JDK available on the system in /usr/jdk/latest.
From time to time, we upgrade the JDK. So, if you have applications that require a specific version you'll of course not want to use /usr/jdk/latest. You can see the other JDK versions available in /usr/jdk.
Update
For Glassfish, you can update /usr/local/glassfish/config/asenv.conf file by adding or changing AS_JAVA="/usr/jdk/latest" to it. That'll also ensure that Glassfish starts up with the correct JRE.