public class ServerBuilder
extends java.lang.Object
Server
.
Use this Builder to set immutable server attributes, then call
the build()
method to build and return a Server
instance.
As an example, to build a new Server
instance, this snippet would suffice:
Server defaultServer = new ServerBuilder().setName("embeddedServer").build();
Constructor and Description |
---|
ServerBuilder() |
Modifier and Type | Method and Description |
---|---|
Server |
build()
Get a new
Server instance. |
ServerBuilder |
setName(java.lang.String serverName)
Set the locally unique name for the server; the name can be constructed
using Unicode alphanumeric characters (for example, A-Za-z0-9), the underscore (_),
dash (-), plus (+) and period (.).
|
ServerBuilder |
setOutputDir(java.io.File outputDir)
Set the path of the user output directory.
|
ServerBuilder |
setServerEventListener(ServerEventListener listener)
Set the listener that will receive
ServerEventListener.ServerEvent notifications. |
ServerBuilder |
setUserDir(java.io.File userDir)
Set the path of the user directory.
|
public ServerBuilder setName(java.lang.String serverName)
serverName
- The name for the server instance.public ServerBuilder setUserDir(java.io.File userDir)
WLP_USER_DIR
environment
variable when launching the server from the command line.
This is optional. By default, the user directory will be wlp/usr
, where
wlp
is the root of the Liberty installation as determined by the
location of the jar providing the server implementation.
This path is referred to by the ${wlp.user.dir}
variable.
The server configuration directory, ${server.config.dir}
,
is equivalent to ${wlp.user.dir}/servers/serverName
.
userDir
- The path to the user directory.public ServerBuilder setOutputDir(java.io.File outputDir)
WLP_OUTPUT_DIR
environment
variable when launching the server from the command line.
This is optional. By default, the user output directory will be ${wlp.user.dir}/servers
.
If this is specified, ${server.output.dir}
will be set to outputDir/serverName
.
Otherwise, ${server.output.dir}
will be the same as ${server.config.dir}
.
outputDir
- The path to the user output directory.setUserDir(File)
public ServerBuilder setServerEventListener(ServerEventListener listener)
ServerEventListener.ServerEvent
notifications.
Using a ServerEventListener
is optional.
listener
- The ServerEventListener
to notify.public Server build() throws ServerException
Server
instance. This will fail if the server does not
already exist (${server.config.dir}
must exist, and must contain
a server.xml
file).ServerException
- if the named server does not exist, or if the attributes
set using the set methods fail validation, e.g. the server name
contains invalid characters, or the provided Files point to existing
files in the file system instead of directories.