I tried to set my context root with the value "new-ctx" in Liberty server config:
server.xml
<application id="my-ear" location="my-ear.ear" name="my-ear" context-root="new-ctx"/>
This was intended to override the setting in my EAR-level pom, which uses maven-ear-plugin to generate an application.xml with context root "old-ctx" for my WAR:
pom.xml (EAR)
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<modules>
<webModule>
<groupId>io.openliberty.guides</groupId>
<artifactId>guide-maven-multimodules-war</artifactId>
<uri>my.war</uri>
<contextRoot>old-ctx</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>
However this didn't work, I still see 'old-ctx':
[INFO] [AUDIT ] CWWKT0016I: Web application available (default_host): http://<host>:9080/old-ctx/
SOLUTION
Add a
<web-ext>
element with acontext-root
attribute as a child element of<application>
, e.g.:server.xml
OR, (using
<enterpriseApplication>
instead of<application>
)NOTE:
The
moduleName
attribute of<web-ext>
should match the<web-uri>
element value (contents) in application.xml.E.g. in my example (though all details are not shown), this application.xml value originates from the
<uri>my.war</uri>
element value within the particular<webModule>
configured via the maven-ear-plugin configuration (since this plugin generates the application.xml).EXPLANATION
The
context-root
attribute of the<application>
is not really used when the<application>
location points to an EAR. This<application>
element has the ability to be used to configure either an EAR or a WAR, and thecontext-root
can be used when configuring a WAR.When configuring an EAR, however, the context root needs to be set on the level of the individual WAR(s) within the EAR, and so something like the
<web-ext>
child element must be used.