You can manually configure your server.xml file to meet the
specifications of your application. By deploying a helloworld.war application,
you can learn how to manually change server configurations in Liberty.
Before you begin
To complete this task, you must provide a helloworld.war application that
uses a simple servlet to display a message on your browser. You can create any other messages to be
displayed. The coding of this application is not described within the Liberty documentation.
However, the Open Liberty Building a web application with Maven guide provides a similar
introduction to deploying an application on Liberty and also includes instructions for
creating a sample application. You can complete that guide as an alternative to supplying your own
helloworld.war application and following the steps in this task.
About this task
When you deploy a web application to Liberty by using the developer tools, all configurations that are related to the application are
automatically enabled in the server.xml file. However, you can also configure
the server.xml file manually by completing the following steps.
This example uses the helloworld.war application and can be accessed by
using http://localhost:9090/helloworld
. In this example, a Liberty server instance is created, and then its
default HTTP port is changed to 9090, and then an application is deployed to it.
Procedure
-
Create a server named
hwserver
by using the command server create hwserver
.
-
Copy the helloworld.war application into the
/usr/servers/hwserver/apps directory; this directory was created by the
server create
command in step 1.
-
In the server.xml file that was created by the
server
create
command, change the default HTTP port of the server hwserver
to
9090 by replacing the attribute value httpPort="9080"
with
httpPort="9090"
.
<server description="new server">
<!-- Enable features -->
<featureManager>
<feature>jsp-2.2</feature>
</featureManager>
<httpEndpoint id="defaultHttpEndpoint"
host="localhost"
httpPort="9090"
httpsPort="9443" />
</server>
-
Configure the application by updating the server.xml in either of the
following ways:
- Define the application by using a
webApplication
element.<server description="Hello World Server">
<featureManager>
<feature>servlet-3.0</feature>
</featureManager>
<httpEndpoint id="defaultHttpEndpoint" host="*" httpPort="9090" />
<webApplication contextRoot="helloworld" location="helloworld.war" />
</server>
- Define the application by using an
application
element.<server description="Hello World Server">
<featureManager>
<feature>servlet-3.0</feature>
</featureManager>
<httpEndpoint id="defaultHttpEndpoint" host="*" httpPort="9090" />
<application context-root="helloworld" type="war" id="helloworld"
location="helloworld.war" name="helloworld"/>
</server>
The webApplication
element can use the same child elements as the
application
element, except for context-root and
type
. The two elements do not work together for a
context-root, and if both an application
and
webApplication
element define the same context-root, only one
is used and an error is displayed.
The
context-root attribute specifies the entry point of the deployed
application. The entry point of a deployed application is determined in the following precedence:
Note: In an application server
server.xml configuration, the
application
element can contain a
context-root tag. This
context-root tag is applicable in combination with the tag
type="war"
. For all other application types, the
context-root
element has no effect.
It is not possible to override the context-root for
either an EAR application, or an EBA application. It is only possible to do an override for a
stand-alone war file, or webApplication
.
-
Start the server in foreground by using
the command
server run hwserver
.
-
Test the application at
http://localhost:9090/helloworld
.
- Optional:
Stop the server if you do
not need it.