How to deploy a Web application on the Root Context on WildFly?

WildFly users

To deploy an application on the ROOT Web context, firstly you have to remove the default Welcome application from undertow’s server:

/subsystem=undertow/server=default-server/host=default-host/location=\/:remove
{
    "outcome" => "success",
    "response-headers" => {
        "operation-requires-reload" => true,
        "process-state" => "reload-required"
    }
}

Reload the server:

reload

Next, if you can either set the ROOT Web context in your application’s jboss-web.xml:

<jboss-web>
    <context-root>/</context-root>
</jboss-web>

As an alternative, you can set the default-web-module of your undertow host as follows:

/subsystem=undertow/server=default-server/host=default-host:write-attribute(name=default-web-module, value=helloworld.war)

You can also specify as default web module a Web application that is packaged as module in an EAR file:

<host name="default-host" alias="localhost" default-web-module="App.ear.demoroot.war">
    <location name="/" handler="welcome-content"/>
    <filter-ref name="server-header"/>
    <filter-ref name="x-powered-by-header"/>
</host>

JBoss AS 7 / EAP 6 Users

At first you need to set in your standalone/domain configuration file the enable-welcome-root parameter to false (by default it’s true) for the web subsystem. The enable-welcome-root controls whether or not to deploy JBoss’ welcome-content application at root context.

<subsystem xmlns="urn:jboss:domain:web:1.0" default-virtual-server="default-host">
    <connector name="http" protocol="HTTP/1.1" socket-binding="http" scheme="http"/>
    <virtual-server name="default-host" enable-welcome-root="false">

</subsystem>

Next, you need telling to the Web server to deploy your application on the Root context. For Web applications the standard Web context can be overriden using the jboss-web.xml file descriptor:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
      http://www.jboss.com/xml/ns/javaee
      http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">
   <context-root>/</context-root>
</jboss-web>

If you are using an Enterprise Application Archive then you can set the Web application context in your application.xml using the <context-root>element of the <web> module as follows:

<application version="5" xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
      http://java.sun.com/xml/ns/javaee
      http://java.sun.com/xml/ns/javaee/application_5.xsd">
   <module>
      <ejb>sample-ejb.jar</ejb>
   </module>
   <module>
      <web>
         <web-uri>sample-webapp.war</web-uri>
         <context-root>/</context-root>
      </web>
   </module>
</application>
Found the article helpful? if so please follow us on Socials