title: Programmatically administer Glassfish domain
body: <p>I need to start, stop, set options on, etc. a glassfish domain in a programmatic way. The only resource I necessarily have available is <code>asadmin</code>. Hence I can</p>
  
  <pre><code>$ asadmin  list-domains
  Foo running
  domain1 not running
  Command list-domains executed successfully.
  </code></pre>
  
  <p>However, I can't see any way to actually tell asadmin how to talk to a domain other than the default domain, <code>Foo</code> in this case. To do so I need to know the port of <code>Foo</code>'s administration server, and there doesn't seem to be any way to get that information. I could theoretically parse <code>Foo</code>'s <code>domain.xml</code>, but to do that I need to know where it is.</p>
  
  <p>Ideally there'd be an <code>asadmin</code> option like <code>--domain Foo</code>, or at least a way to get <code>Foo</code>'s port or directory, but I can't seem to find anything along those lines. </p>
  
  <p>Advice appreciated...</p>
  
  <pre><code>$ asadmin version
  Version string could not be obtained from Server [localhost:4848] for some reason.
  (Turn debugging on e.g. by setting AS_DEBUG=true in your environment, to see the details).
  Using locally retrieved version string from version class.
  Version = GlassFish Server Open Source Edition 3.1.2.2 (build 5)
  Command version executed successfully.
  </code></pre>
  
  <p><strong>UPDATE:</strong> For now I'm using the filthy hack of determining the location of domain.xml via <code>which asadmin</code> and chopping up the path. Then I parse the xml and extract the port. This is a terrible solution, so I'm leaving the question open to see if there's anything better.</p>