Oracle GlassFish Server 3.0.1 Embedded Server Guide

Setting the Port of an Embedded GlassFish Server From an Application

You must set the server's HTTP port. If you do not set the port, your application fails to start and throws an exception. You can set the port directly or indirectly.


Example 3 Starting an Embedded GlassFish Server

This example shows code for setting the port of an embedded GlassFish Server. This example also includes the code from Example 1 for creating Server.Builder and Server objects.

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