Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Context path for web application on Glassfish 3.1.2.2

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:

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.

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:

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.

The web.xml for FooApp looks as follows:

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <context-param>
        <param-name>defaultWebRootId</param-name>
        <param-value>2631</param-value>
    </context-param>

    <listener>
        <listener-class>com.foo.service.AppInitialiser</listener-class>
    </listener>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
</web-app>

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.

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?

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.

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.

like image 912
PhilDin Avatar asked Aug 07 '12 20:08

PhilDin


People also ask

Where is context path in web application?

The typical way of getting the context path is through the HttpServletRequest class. Simply you can add a HttpServletRequest parameter to your controller method and then get the context path using getContextPath() method. Now that you get the context path, you can pass it to the services that need it.

How do I change the context path of a web application?

To change the context root of a web application that is already available in the Eclipse workspace, simply right-click on the web project and call the “Properties” action from the context menu.

What is context path in Java web application?

The context path is the portion of the request URI that is used to select the context of the request. The context path always comes first in a request URI. The path starts with a "/" character but does not end with a "/" character. For servlets in the default (root) context, this method returns "".

What is context root path?

A context root identifies a Web application archive (WAR) file in an application server. The context root of a Web application determines which URLs application server will delegate to your web application. When MobileFabric installed, the required components' WARs are deployed to an app server.


1 Answers

Add a glassfish-web.xml file in the same folder as web.xml

<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
    <context-root>/FooWS</context-root>
</glassfish-web-app>
like image 105
Alf Avatar answered Nov 15 '22 22:11

Alf