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 set the port directly, invoke the createPort method of the Server object.
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 Enterprise Server File System and Using an Existing domain.xml File.
This example shows code for setting the port of an embedded Enterprise 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); ...