Is it possible to override the root context specified in WEB-INF/jboss-web.xml at deploy time?
I have this jboss-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<context-root>my-context</context-root>
</jboss-web>
And I want to be able to deploy the application with different root context in in e.g. /another-context for some of my environments, but keep /my-context in other environments.
You can do this via WildFly Maven Plugin (as part of your CI job) or using the WildFly CLI.
The maven variant would be like the following command:
org.wildfly.plugins:wildfly-maven-plugin:deploy-only
-Dwildfly.deployment.filename=app.war
-Dwildfly.deployment.runtime.name=appcontext.war
The app will be deployed under /appcontext.
Note, you should remove the context-root from your jboss-web.xml otherwise this value will win always.
The CLI variant could look like (documentation):
[dply@as wildfly-8.2.0.Final]$ bin/jboss-cli.sh
You are disconnected at the moment. Type 'connect' to connect to the server or 'help' for the list of supported commands.
[disconnected /] connect
[standalone@localhost:9990 /] deploy /path/to/app.war --runtime-name=appcontext.war
For doing this, you could combine maven profiles (e.g. "my-context" and "another-context") and maven resource filtering as explained here: Maven resource filters
It certainly takes a little bit of time until everything works as expected.
if you have a EAR file you need to define it at your application.xml
<module>
<web>
<web-uri>webapp.war</web-uri>
<context-root>/my-context</context-root>
</web>
</module>