I tried to set my context root with the value "new-ctx" in Liberty server config:
<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:
<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/
Add a <web-ext>
element with a context-root
attribute as a child element of <application>
, e.g.:
<application id="my-ear" location="my-ear.ear" name="my-ear">
<web-ext moduleName="my.war" context-root="new-ctx"/>
</application>
OR, (using <enterpriseApplication>
instead of <application>
)
<enterpriseApplication id="my-ear" location="my-ear.ear" name="my-ear">
<web-ext moduleName="my.war" context-root="new-ctx"/>
</enterpriseApplication>
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).
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 the context-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.