WebSphere Tutorial · WebSphere Liberty · Lesson 7 of 23

Deploying Applications

Deploying WAR and EAR files to Liberty: apps/ with application elements versus dropins/, context roots and application settings.

Members can save this page, take notes and track progress. See membership · Sign in

Two ways to deploy

  • dropins/: copy a WAR or EAR in and Liberty starts it with default settings. Great for experiments.
  • apps/ plus an element in server.xml: name the application and control its context root, class loader, security roles and bindings. Use this in real environments.
<webApplication id="orders" location="orders.war" contextRoot="/orders">
  <classloader commonLibraryRef="sharedLibs"/>
</webApplication>
<enterpriseApplication location="billing.ear">
  <application-bnd>
    <security-role name="admin"><group name="billing-admins"/></security-role>
  </application-bnd>
</enterpriseApplication>

WAR or EAR?

A WAR holds one web module (servlets, REST, static files, its libraries in WEB-INF/lib). An EAR bundles several modules (WARs, EJB JARs) with shared libraries. New services are usually single WARs; EARs are common in existing enterprise applications.

How the context root decides an application's URLTry it yourself
def url_for(app, context_root=None, port=9080):
    root = context_root if context_root is not None else "/" + app.rsplit(".", 1)[0]
    return f"http://localhost:{port}{root.rstrip('/') or ''}/"

for app, root in [("orders.war", None), ("orders.war", "/"), ("orders.war", "/api/orders")]:
    how = "dropins default" if root is None else f"contextRoot={root}"
    print(f"{app:11} {how:24} -> {url_for(app, root)}")

Output

orders.war  dropins default          -> http://localhost:9080/orders/
orders.war  contextRoot=/            -> http://localhost:9080/
orders.war  contextRoot=/api/orders  -> http://localhost:9080/api/orders/

Test yourself

Why prefer apps/ with an application element over dropins/ in production?

  1. dropins/ doesn't support WAR files
  2. It names the application and lets you set context root, class loading, security and bindings
  3. apps/ starts faster
  4. dropins/ is only for EAR files
Show answer

Answer: It names the application and lets you set context root, class loading, security and bindings

Explicit configuration is reproducible and controllable.

Last reviewed · By the ByteCamel team · How we write content

Was this page helpful?

Report a mistake