Deploy Application on Websphere Liberty

Share on:

Deployment

From an operational perspective deploying web applications is a very easy process in WebSphere Liberty. The server supports two modes of deployment.

  • Deploy the application by dropping it in dropin directory
  • Deploy the application by adding to server configuration file in server.xml file

By default WebSphere Liberty has defaultServer server which can use for deployment or its easy to create a server on our own.

We should follow only one procedure for deployment, if you drop applicaiton in dropin directory and update server.xml file, then server will load the applicaiton twise.

Create Server:

./server create myfirstserver

naga@naga-virtualbox2:~/wlp/bin$ ./server create myfirstserver
Server myfirstserver created.
After creating server folder structure look like as
naga@naga-virtualbox2:~/wlp/usr/servers/myfirstserver$ ls -lart
total 36
-rw-rw---- 1 naga naga  552 May  1 12:23 server.xml
-rw-rw---- 1 naga naga   41 May  1 12:23 server.env
drwxr-xr-x 7 naga naga 4096 May  2 18:39 ..
drwxrwx--- 5 naga naga 4096 May  3 15:09 workarea
drwxrwx--- 3 naga naga 4096 May  3 15:10 resources
drwxrwx--- 7 naga naga 4096 May  3 15:10 .
drwxrwx--- 3 naga naga 4096 May  3 15:10 logs
drwxrwx--- 2 naga naga 4096 May  3 15:12 dropins
drwxrwx--- 3 naga naga 4096 May  3 15:12 apps

Start Server:

./server start myfirstserver

1naga@naga-virtualbox2:~/wlp/bin$ ./server start myfirstserver
2Starting server myfirstserver.
3Server myfirstserver started with process ID 2786.

Detailed Log files can find below log folder with in newly created server folder

naga@naga-virtualbox2:~/wlp/usr/servers/myfirstserver/logs$ ls -lart
total 28
drwxrwx--- 7 naga naga 4096 May  3 15:10 ..
drwxrwx--- 3 naga naga 4096 May  3 15:10 .
-rw-rw---- 1 naga naga 1648 May  3 15:12 console.log
drwxrwx--- 2 naga naga 4096 May  3 15:12 state
-rw-rw---- 1 naga naga 8617 May  3 15:13 messages.log

tail of log file as messages.log

[5/3/20 15:49:41:862 CEST] 00000025 com.ibm.ws.kernel.feature.internal.FeatureManager            A CWWKF0012I: The server installed the following features: [appSecurity-2.0, appSecurity-3.0, beanValidation-2.0, cdi-2.0, distributedMap-1.0, ejbLite-3.2, el-3.0, jaspic-1.1, jaxrs-2.1, jaxrsClient-2.1, jdbc-4.2, jndi-1.0, jpa-2.2, jpaContainer-2.2, jsf-2.3, jsonb-1.0, jsonp-1.1, jsp-2.3, managedBeans-1.0, servlet-4.0, ssl-1.0, webProfile-8.0, websocket-1.1].
[5/3/20 15:49:41:870 CEST] 00000025 com.ibm.ws.kernel.feature.internal.FeatureManager            I CWWKF0008I: Feature update completed in 14.693 seconds.
[5/3/20 15:49:41:886 CEST] 00000025 com.ibm.ws.kernel.feature.internal.FeatureManager            A CWWKF0011I: The myfirstserver server is ready to run a smarter planet. The myfirstserver server started in 20.836 seconds.
[5/3/20 15:49:43:677 CEST] 0000001f com.ibm.ws.ssl.config.WSKeyStore                             A CWPKI0820A: The default keystore has been created using the 'keystore_password' environment variable.
[5/3/20 15:49:46:261 CEST] 0000001f com.ibm.ws.ssl.config.WSKeyStore                             I Successfully loaded default keystore: /home/naga/Downloads/wlp/usr/servers/myfirstserver/resources/security/key.p12 of type: PKCS12
[5/3/20 15:49:47:356 CEST] 0000002d com.ibm.ws.tcpchannel.internal.TCPPort                       I CWWKO0219I: TCP Channel defaultHttpEndpoint-ssl has been started and is now listening for requests on host localhost  (IPv4: 127.0.0.1) port 9443.

Deploy Application:

Copy WAR file into droppin directory of the newly created server. A simple HelloWorld.war file can get from GitHub, HelloWorld.war

naga@naga-virtualbox2:~/Downloads/wlp/usr/servers/myfirstserver/dropins$ wget https://github.com/middlewaretrace/wlp/blob/master/HelloWorld.war

As soon copying the war file, logs get an update with the below message that the server is listening droppings directory for any change in the content. But after copying war file server configuration has to update with appropriate reference.

[5/3/20 15:53:12:479 CEST] 00000059 com.ibm.ws.artifact.zip.internal.ZipFileContainerFactory     E CWWKM0101E: The system could not process archive data for /home/naga/Downloads/wlp/usr/servers/myfirstserver/dropins/HelloWorld.war.
[5/3/20 15:53:12:510 CEST] 00000059 com.ibm.ws.app.manager.AppMessageHelper                      E CWWKZ0021E: The server is not configured to handle the resource at location /home/naga/Downloads/wlp/usr/servers/myfirstserver/dropins/HelloWorld.war.

For this, update server.xml file with application reference. There are many tags in server.xml which will discuss incoming topics. For now, as we are configuring WebApplication, add its appropriate tag with the name of the application and its unique id.

 1<?xml version="1.0" encoding="UTF-8"?>
 2<server description="new server">
 3    <!-- Enable features -->
 4    <featureManager>
 5        <feature>webProfile-8.0</feature>
 6    </featureManager>
 7    <!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
 8    <httpEndpoint id="defaultHttpEndpoint"
 9                  httpPort="9080"
10                  httpsPort="9443" />
11
12    <!-- Automatically expand WAR files and EAR files -->
13    <applicationManager autoExpand="true"/>
14    <webApplicaiton id="HelloWorld" location="HelloWorld.war" name="HelloWorld" />
15</server>

As soon update the configuration file it automatically takes the application and starts listening to the port.

 1[5/3/20 16:05:53:579 CEST] 0000003b org.jboss.weld.Version                                       I WELD-000900: 3.1.1 (Final)
 2[5/3/20 16:05:53:956 CEST] 0000003b com.ibm.ws.webcontainer.osgi.webapp.WebGroup                 I SRVE0169I: Loading Web Module: HelloWorld.
 3[5/3/20 16:05:53:960 CEST] 0000003b com.ibm.ws.webcontainer                                      I SRVE0250I: Web Module HelloWorld has been bound to default_host.
 4[5/3/20 16:05:53:961 CEST] 0000003b com.ibm.ws.http.internal.VirtualHostImpl                     A CWWKT0016I: Web application available (default_host): http://localhost:9080/HelloWorld/
 5[5/3/20 16:05:53:985 CEST] 0000003b com.ibm.ws.app.manager.AppMessageHelper                      A CWWKZ0001I: Application HelloWorld started in 0.739 seconds.
 6[5/3/20 16:05:54:084 CEST] 00000037 com.ibm.ws.session.WASSessionCore                            I SESN0176I: A new session context will be created for application key default_host/HelloWorld
 7[5/3/20 16:05:54:096 CEST] 00000037 com.ibm.ws.util                                              I SESN0172I: The session manager is using the Java default SecureRandom implementation for session ID generation.
 8[5/3/20 16:05:54:161 CEST] 00000037 org.hibernate.validator.internal.util.Version                I HV000001: Hibernate Validator 6.1.1.Final
 9[5/3/20 16:05:54:176 CEST] 00000034 com.ibm.ws.webcontainer.osgi.mbeans.PluginGenerator          I SRVE9103I: A configuration file for a web server plugin was automatically generated for this server at /home/naga/Downloads/wlp/usr/servers/myfirstserver/logs/state/plugin-cfg.xml.
10[5/3/20 16:05:54:347 CEST] 00000037 com.ibm.ws.cache.CacheServiceImpl                            I DYNA1056I: Dynamic Cache (object cache) initialized successfully.
11[5/3/20 16:05:54:365 CEST] 00000037 org.apache.myfaces.ee.MyFacesContainerInitializer            I Using org.apache.myfaces.ee.MyFacesContainerInitializer

Now, let's access the application http://localhost:9080/HelloWorld/

Stop server:

./server stop myfirstserver

1naga@naga-virtualbox2:~/wlp/bin$ ./server stop myfirstserver
2Stopping server myfirstserver.
3Server myfirstserver stopped.
comments powered by Disqus