I am building a java web application using Eclipse
and Maven
. The app will run on either jboss
(wildfly
) or tomcat
. I would like to configure the context path of my web application.
By default, eclipse sets the context path to be equal to the name of the eclipse project (seen in project -> properties -> web project settings
). However, regardless of the context path shown there, when I deploy my war file, the name of the war file is used as the context path, not the setting in eclipse.
I would like to know how to configure the context path in the following three situations:
Is the context path chosen platform / eclipse / servlet container dependent? Has anybody documented the standard behavior of each container? Is there a way to configure/set the context path for all platforms and servlet containers, regardless of how and where the war is build/deployed, and more importantly, so the war name is NOT the same as the context path?
The only way so far to set the context-root of a WAR so that it is independent of the application server being used is : make it a part of an EAR and supply the context-root via application.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" version="6">
<display-name>EAR_NAME</display-name>
<module id="Module_***********">
<web>
<web-uri>YourWeb.war</web-uri>
<context-root>YourContextRoot</context-root>
</web>
</module>
</application>
Even as of JAVA EE 6, the WAR's context-root has to be a part of either jboss-web.xml
, glassfish-web.xml
or similar server specific web deployment descriptor. Here is an official example.
I could not find similar example for JAVA EE 7, but i really don't think this has changed. JEE7 was mostly about adding features around HTML5 and JSON.