Tuesday, May 27, 2008

Glassfish and Windows Service

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.

7 comments:

  1. There is also a tool to help with this:

    http://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.

    ReplyDelete
  2. 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\...'.

    ReplyDelete
  3. good

    http://www.justinjacob.com

    ReplyDelete
  4. The tool doesn't appear to work on GlassFish v3 though. Anything that works on the latest greatest?

    ReplyDelete
  5. just try this:

    c:\glassfishv3\bin\asadmin create-service

    works like a champ

    ReplyDelete
  6. Great solution for Glassfish v2. Thanks!

    ReplyDelete