How to deploy war file in root(/) context to Wildfly ver 9.0.1

This is a solution for those using Maven in their projects. To make Wildfly host your application under /, you have to name the war file containing the application as "ROOT.war". To automate this action, change the default war file name in your pom.xml to ROOT like this:

...
</dependencies>
<build>
    <!-- <finalName>${project.artifactId}</finalName> -->
    <finalName>ROOT</finalName>

This way, when deploying the application to Wildfly using Maven, the file is automatically hosted in the root.


Two files have to be added in WEB-INF folder before creating a war file

  1. jboss-web.xml

    <?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>
    
  2. empty bean.xml


To override the welcome webapp with Wildfly, you need to create a jboss-web.xml in the WEB-INF of your webapp with this content:

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

But if you try to access to the root directory (e.g. http://localhost:8080/) you will still have the default welcome content. To remove it, you just need to rename the directory welcome-content in the Wildfly directory.