A common requirement whilst developing an application is to run your application in an expanded format. The easiest and quickest way is to put that application into the dropins directory in the server’s configuration directory. This automatically deploys your application to your Liberty server. Alternatively, you can put the application in the apps directory in the server’s configuration directory and add an entry to the server’s server.xml. This means you have more control over certain aspects like security bindings or classloader delegation. By default, Liberty looks in both directories for applications.

In this article, we use a WAR file but the steps described also apply to other types of application (e.g. EAR files).

Setting up the application

We’ll start by setting up a simple application, the Default Servlet Engine, which has a deployed application in the dropins folder:

  1. Download the DefaultServletEngine sample.
  2. Unzip the DefaultServletEngine.zip into the servers directory of your server configuration. By default this will be in the usr directory of your Liberty installation.
  3. Start the server by running the command server run DefaultServletEngine in the bin directory.
  4. Navigate to this URL http://localhost:9080/Sample1/SimpleServlet and ensure you see a webpage. If you changed the hostname or port you will need to change these.

Deploy to the apps directory

The application above will work fine but in some situations it may be preferable to deploy an application to Liberty with more control. To do this, move your application to the apps directory and configure it:

  1. Go to the Sample1.war application in the dropins directory, and move it to the apps directory. You will find the apps directory at the same level as the dropins directory (*WLP_install_root*/usr/servers/DefaultServletEngine). Make sure you move the application rather than copy it. If you have the same application in two locations you will see error messages.
  2. Add the following line to the server.xml file:
          <application id="Sample1" location="Sample1.war" name="Sample1"/>
        
  3. Navigate to http://localhost:9080/Sample1/SimpleServlet to see your application.

Expanding the application

Once you have an application in a compressed format, you may wish to expand it out. This will make it easier if you need to make updates to individual files in a development environment:

  1. Unzip the Sample1.war application in the apps directory so that you have a directory called Sample1 that contains a directory called WEB-INF.
  2. Remove the Sample1.war file and rename the Sample1 directory to Sample1.war (in that order).
  3. Navigate to http://localhost:9080/Sample1/SimpleServlet to see your application.
    You do not need to change the server.xml configuration file. The expanded file is treated the same as the compressed format.

Deploy to an alternative location

You may choose to deploy your application from an alternative location; for example, if you want to share the application across multiple servers. This works in a similar way to the previous example but in this case you need to provide a path to your application:

  1. Move the Sample1.war directory from the apps folder to another location on your filesystem. In this example, we will assume you are on Windows and want your applications in a directory at C:sharedApplicationFolder. Make sure there isn’t a copy of the application still in the apps directory. Liberty will only look in the apps directory if you do not specify an absolute path.
  2. Update your application element to point to the new location. For example, if we had the application in C:sharedApplicationFolderSample1.war the server xml entry would look like this:
          <application id="Sample1" location="C:sharedApplicationFolderSample1.war" name="Sample1"/>
        
  3. Navigate to http://localhost:9080/Sample1/SimpleServlet to see your application.

14 comments on"Application deployment in Liberty"

  1. Can I migrate my Java applications wihch are deployed and running on WebSphere Application server 6.1 to Docker Liberty profile ? Is this possible ?

  2. How to deploy an ear file?

    • David Currie April 12, 2017

      You should be able to use the same instructions to deploy an EAR file.

  3. I have an EAR which requires setting PreCompile JavaServer Pages, Disable JSP Runtime Compilation, Unchecking JSP enable class reloading, Initialize parameters for servlets, Virtual Host, Classloader Parent last. How can that be achieve in Liberty?

  4. Does Liberty allow you to deploy applications from a central point of administration like the Deployment Manager? I’m thinking of the scenario where I want to deploy an application and target it to a particular cluster or change certain config across all cluster members. What is the best way to do that in Liberty without going to each individual cluster/collective member to make the changes? Thanks.

    • Hi Kevin – absolutely. In a Liberty collective the collective controllers provide the same function as a central point of administration as the deployment manager in a traditional cell. For example, a controller can act as a JMX proxy for any server in the collective. There are some significant differences though: there can be multiple controllers for starters and the configuration is owned by the individual servers rather than by the controller.

  5. Dave Westerman July 26, 2013

    For the ‘Deploy to the apps directory’ section, step 2 says to add the following line to the server.xml, but the line is missing. I think you want:

    Sample1

    • Jamie_Coleman August 17, 2016

      Hi Dave

      You are correct and the above error has been corrected.

      Thank you for pointing that out!

Join The Discussion

Your email address will not be published. Required fields are marked *