Oracle GlassFish Server 3.0.1 Embedded Server Guide

Creating and Configuring an Embedded GlassFish Server

To create and configure an embedded GlassFish Server, perform these tasks:

  1. Instantiate the org.glassfish.api.embedded.Server.Builder class.

  2. Invoke any methods for configuration settings that you require. This is optional.

  3. Invoke one of the build methods to create a Server object.

The methods of this class for setting the server configuration are listed in the following table. The default value of each configuration setting is also listed.

Table 1 Constructor and Methods of the Server.Builder Class

Purpose 

Method 

Default Value 

Creates a server builder and names the server 


Server.Builder(java.lang.String id)

None 

References an embedded file system 


embeddedFileSystem(EmbeddedFileSystem file-system)

None 

Enables verbose mode 


verbose(boolean enabled)

true

Enables logging 


logger(boolean enabled)

true

Specifies a log file 


logFile(File log-file)

domain-dir/logs/server.log (see Instance Root Directory)

Creates a server 


build()

None 

Creates a server with properties 


build(Properties properties)

None 


Example 1 Creating an Embedded GlassFish Server

This example shows code for creating a server and enabling logging.

...
import org.glassfish.api.embedded.*;
...
    Server.Builder builder = new Server.Builder("test");
    builder.logger(true);
    ...
    Server server = builder.build();
...