JBossAS7 has such a small resource footprint that I can’t think of any good reason not to just have it running all the time as a background daemon. And it saves me having to have a terminal instance open to run it in. So I added it to my user launchd configuration.

To do this:

  1. Create a launched plist file.

    This file contains the configuration that is used to launch and handle the AS7 process. Here is the file I am using. I saved it as jboss.plist.

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
       "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
       <dict>
          <key>Label</key>
          <string>jboss</string>
          <key>Disabled</key>
          <false/>
          <key>KeepAlive</key>
             <dict>
                <key>SuccessfulExit</key>
                <false/>
             </dict>
          <key>Program</key>
          <string>/Users/tabby/Library/jboss-as-7.1.1.Final/bin/standalone.sh</string>
          <key>StandardOutPath</key>
          <string>/Users/tabby/Library/jboss-as-7.1.1.Final/out.log</string>
          <key>RunAtLoad</key>
          <true/>
          <key>UserName</key>
          <string>tabby</string>
       </dict>
    </plist>
    

    Program is the command that will be used to launch the process, so either standalone.sh or domain.sh. I don’t know if there is any trick if you want to supply command line parameters - exercise for the student ;-).

    StandardOutPath is the file where the console output of the server ends up.

  2. Add this configuration into launched with the launchctl command.

    [localhost]$ launchctl load jboss.plist</code>
    

Done. launched will start the server process immediately and will also do so when you login. When you logout the process is terminated. This is fine for running it for your own use. If you run this command with sudo then it will add it to the system launchd configuration and start the process when the OS loads.

If you are using Eclipse and JBoss Tools, when you create a server instance in the IDE remember to select the “Server is externally managed. Assume server is started.” checkbox. Otherwise the IDE will attempt to launch another instance of the server, which will fail due to port conflicts.

Wikipedia article about launchd: http://en.wikipedia.org/wiki/Launchd

Very detailed post about launchd: http://www.afp548.com/article.php?story=20050620071558293

Stackoverflow question where I got my config sourced from: http://stackoverflow.com/questions/9604875/anyone-have-a-launchd-script-for-running-jboss-at-boot-on-mac-osx-lion