title: Context path for web application on Glassfish 3.1.2.2
body: <p>I'm trying to find a way to explicitly specify the context path of a web application being deployed to Glassfish 3.1.2.2 but I've had no luck so far. Can anyone provide guidance on this? The background to this is below:</p>
  
  <p>I have a web application that consists of two separate Netbeans (7.0) projects. The first is a web service and is called FooWS. The second is a user facing web application which uses the FooWS webservice. It's called FooApp. </p>
  
  <p>I've recently upgraded glassfish to 3.1.2.2 in the hope of resolving some other issue and now when I deploy the FooWS app, it deploys successfully but with the context path /web rather than /FooWS. This is not something I would particularly care about except that when I try to deploy FooApp, glassfish also tries to deploy that to /web leading to the following error:</p>
  
  <p>SEVERE: Exception while loading the app : java.lang.Exception: WEB0113: Virtual server [server] already has a web module [FooWS] loaded at [/web]; therefore web module [FooApp] cannot be loaded at this context path on this virtual server. </p>
  
  <p>The web.xml for FooApp looks as follows:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="3.0" 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/web-app_3_0.xsd"&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;defaultWebRootId&lt;/param-name&gt;
          &lt;param-value&gt;2631&lt;/param-value&gt;
      &lt;/context-param&gt;
  
      &lt;listener&gt;
          &lt;listener-class&gt;com.foo.service.AppInitialiser&lt;/listener-class&gt;
      &lt;/listener&gt;
      &lt;session-config&gt;
          &lt;session-timeout&gt;
              30
          &lt;/session-timeout&gt;
      &lt;/session-config&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>The configuration for FooWS is similar. Neither contains any mention of the application context so my expectation is that it should use /FooWS rather than default to /web. </p>
  
  <p>The obvious solution would seem to be to override the context path in the web.xml but I can't find any way of doing this. Any suggestions? </p>
  
  <p>Just some follow up, I accidentally changed the context path to /FooW. This time it deployed as expected to /FooW. Changing it back if /FooWS causes the old behaviour to return, that is, it deploys again to /web. It seems like I have a workaround for the moment. </p>
  
  <p>For the benefit of anyone following this, I got the same behaviour with 3.1.2. I have now returned to 3.1 (b43) and it behaves as expected.</p>