How to deploy a Web application on the Root Context on JBoss AS 7 and WildFly?

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>

WildFly users

For WildFly users it's enough to include in jboss-web.xml the Root Web context ("/") as it will disable by default the Welcome page. Easy peasy!

<?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>

Related articles available on mastertheboss.com

How do I reload dynamically my jsp from an ear ?

  Deploy your Jsp as part of an application deployed in exploded

Where is my compiled JSP ?

JBoss recipe of the day

How do you configure JBoss to enable HTTP logging ?

To enable HTTP logging, you need to go to the deploy/jbossweb-tom

JBoss Struts tutorial

This article explains how you can setup quickly an application ba

How to restrict access to JBoss web application by IP or Host?

You can create easily Access control list based on the IP address

How do you configure a Web Application as Default Web app ?

  JBoss AS 4-5-6 First you have to remove the default

Follow us on Twitter