Starting glassfish with a Windows service

Glassfish is a Java Enterprise Edition application server. If it is installed on a windows server it is necessary start it automatically, for example after a maintenance reboot. To achieve this goal the glassfish startup process has to be performed with a windows service.
1 answer

Creating a Windows service for Glassfish

Steps

  1. Install a Glassfish Applications server from http://www.oracle.com/technetwork/middleware/glassfish/downloads/index.html
  2. Open a Windows Command Line: Start Menu -> Run
  3. Change to your glassfish/bin directory

    cd $GLASSFISH/bin
  4. Execute the following command (for Glassfish v3):

    asadmin create-service --name "$SERVICENAME" $DOMAIN

    $SERVICENAME ... the name of your Windows service
    $DOMAIN... the name of your application domain in the glassfish
  5. Execute the following command (for Glassfish v2):

    C:\WINDOWS\system32\sc.exe create $SERVICENAME binPath= "$glassfish-root\lib\appservService.exe \"$glassfish-root\bin\asadmin.bat start-domain --user admin --passwordfile $glassfish-root\passwordfile $DOMAIN\" \"$glassfish-root\bin\asadmin.bat stop-domain $DOMAIN\"" start=auto DisplayName="$DISPLAYNAME"

    $SERVICENAME ... the name of your Windows service
    $DOMAIN... the name of your application domain in the glassfish
  6. Check if your windows service was created correctly and set to start automatically:
    1. Goto: Start -> Administrative Tools -> Services
    2. Right klick on your service and select properties
    3. Check if Startup typ is set to Autmatic
  7. Klick Start, to start the service

Commands (only Glassfish v3)

  • To start the service from commandline: /path/to/$SERVICENAME start
  • To stop the service from commandline: /path/to/$SERVICENAME stop