If you want to automatically restart a Glassfish domain on Windows platform, you need to pay attention to some dirty details:
1) Try not to install Glassfish under a directory with space. It will save you some troubles down the road. If you happen not to do so the first hand, be prepared to customize the following script to set up the Windows Service:
C:\windows\system32\sc.exe create domain1 binPath= "C:\Program Files\glassfish-v2ur1\lib\appservService.exe \"\\\"C:\Program Files\glassfish-v2ur1\bin\asadmin.bat\\\" start-domain --user admin domain1\" \"\\\"C:\Program Files\glassfish-v2ur1\bin\asadmin.bat\\\" stop-domain domain1\\\"" start= auto type= own type= interact DisplayName= "Glassfish"
Please pay special attention to those ugly escapes characters.
2) When you log out of Windows, the java.exe will stop while the Windows Service is still running. The JVM shuts itself down upon the user logout event. This "feature" can be disabled by modifying the Glassfish's domains\domain1\config\domain.xml. Open the file and search for jvm-options; add a new line at the bottom of the options for the new -Xrs JVM option following the format in the file; save the file and finally restart the Glassfish Windows Service to activate the change.
There is also a tool to help with this:
ReplyDeletehttp://wiki.glassfish.java.net/Wiki.jsp?page=FaqRunAsWindowsService
Don't forget to add the -Xrs jvm option to domain.xml so that the JVM doesn't shut down when you log out of Windows.
After reviewing the source code of that tool, it's interesting to notice that, the tool and this command line are doing exactly the same thing to resolve the same problem: add some messy escape characters to compensate the space in 'C:\Program Files\...'.
ReplyDeletegood
ReplyDeletehttp://www.justinjacob.com
The tool doesn't appear to work on GlassFish v3 though. Anything that works on the latest greatest?
ReplyDeletejust try this:
ReplyDeletec:\glassfishv3\bin\asadmin create-service
works like a champ
Great solution for Glassfish v2. Thanks!
ReplyDeleteThanks a lot!
ReplyDelete