Oracle GlassFish Server 3.0.1 Embedded Server Guide

Stopping an Embedded GlassFish Server From an Application

The API for embedded GlassFish Server provides a method for stopping an embedded server. Using this method enables your application to stop the server in an orderly fashion by performing any necessary cleanup steps before stopping the server, for example:

To stop an embedded GlassFish Server, invoke the stop method of an existing Server object.

Example 5 Stopping an Embedded GlassFish Server

This example shows code for prompting the user to press the Enter key to stop an embedded GlassFish Server. When a user presses Enter, the application undeploys any deployed applications before stopping the server. For more information about undeploying applications, see Undeploying an Application. Code for creating a Server object is not shown in this example. For an example of code for creating a Server object, see Example 1.

import org.glassfish.api.embedded.*;
    EmbeddedDeployer deployer = server.getDeployer();
    System.out.println("Press Enter to stop server");
        // wait for Enter
    new BufferedReader(new;