Note, there are two parts, one is starting, other is stopping.
Also, these are the ways I know of. There could be others. But these are official GlassFish public interfaces.
Way to start the server Benefits/limitations
1) asadmin start-domain - Works with any domain.
- Reads domain.xml for any java-config
data.
- May take longer as 3 processes are
involved in the default case. The
number reduces to 2 with --verbose. With
--verbose, ^C on terminal (On Unix e.g.)
will end the server process.
- Starts any domain on given file system.
2) java -jar glassfish-x.jar - Starts the VM that server uses, directly.
(where x is the version) - You undertake the responsibility of
setting VM parameters on command line.
- If you are invoking it from another
Java process, you get a sub-process
handle(e.g. instance of java.lang.Process)
that you can optionally destroy. You can
also redirect standard process streams.
- Meant for power users.
3) Call embedded API from within - Meant only for embedded use.
your desktop/console application - Domain.xml configuration is irrelevant
and is not consulted for Java command
line options while server starts.
- No VM overhead, uses resources from your
("embedding") VM.
4) Invoking <install>/bin/startserv - Shortcut for 1) with --verbose. Thus by
default "startserv" would start the
default domain in verbose mode.
- Parametrized to deal with any domain. e.g.
startserv --domaindir /Users/kedar mydom
would start a domain named "mydom" in
folder "/Users/kedar" in verbose mode.
- You can use ^C to stop such a process.
In non-embedded case, recommended way of starting the domain/server is 1),
followed by 4).
Way to stop the server Benefits/limitations
1) asadmin stop-domain - Stops any domain, "domain1" by default.
- Causes System.exit() called in server
since --force is true by default.
2) ^C on a console after - Easy enough.
using 1) with --verbose, - Instant gratification ;) .
2) or 4) above to start
3) stopserv - Does exact opposite of startserv,
parametrized same way.
- Needs another shell to issue the command.
4) http://host:port/stop-domain - Can be invoked from browser.
5) Using embedded API - Meant only for embedded case. I don't know
details of it. Ask Byron/Kohsuke/Vivekp.
6) Using MBeans (AMX) - get DomainRoot MBean, then call domainRoot.executeREST(DomainRoot.STOP_DOMAIN);
In non-embedded case, recommended way is 1), followed by 3) and then 2, 4.