Issue
I am using the Maven WildFly plugin and have the following in my pom.xml
(version is 2.0.1.Final
and path points to a local WildFly 8.2.1.Final
server).
<build>
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>${wildfly.version}</version>
<configuration>
<jboss-home>${wildfly.path}</jboss-home>
</configuration>
</plugin>
</plugins>
</build>
The application is getting deployed as localhost:8080/myArtifactId-myVersion
which is expected as the default behavior is to use the WAR name. However, I want to change the context root so that the application is accessible via localhost:8080/
(i.e. I want a blank context root).
Method 1: Change the Pom Configuration
I can change the finalName
build setting in my pom.xml
as follows.
<build>
<finalName>newContextRoot</finalName>
</build>
This correctly updates the url to localhost:8080/newContextRoot
. I then tried to change it to be a blank value.
<build>
<finalName></finalName>
</build>
However, this results in a Value must not be empty
error in my IDE and when I try to build it fails, saying Error assembling WAR: A zip file cannot include itself
.
Method 2: Change Plugin Configuration
Probably the better solution is to change the configuration of the Maven WildFly plugin itself. Under the <configuration>
section, I can add the following.
<name>anotherContextRoot.war</name>
This correctly changes the url to localhost:8080/anotherContextRoot
. So then I tried again to create a blank name as in the following.
<name>.war</name>
However, this results in an IllegalArgumentException: Empty name segment is not allowed for module
.
Question
Does anyone know the appropriate way to make the context root blank? Thanks in advance.
Solution
I managed to figure this out. You do not need to do anything except add a jboss-web.xml
file into the WEB-INF
directory as follows.
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<context-root>/</context-root>
<default-encoding>UTF-8</default-encoding>
</jboss-web>
This sets the context root and overrides what the plugin was doing.
Hope this helps someone else.
Answered By - Snowy Coder Girl
Answer Checked By - Marie Seifert (JavaFixing Admin)