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.
To port indirectly, set up an embedded file system, which includes a domain.xml file that sets the port. For more information, see Specifying an Embedded GlassFish Server File System and Using an Existing domain.xml File.
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); ...