Using contextual root from glassfish-web.xml in GlassFish 3

We recently switched to Glassfish 3.1.2.2 and you have several web applications packaged as war files. Sometimes the desired root context for these applications is different from the file name.

Back when we used Weblogic, we achieved this by declaring the root context in weblogic.xml, like this

<context-root>path/to/our/App</context-root>

We noticed that the same tags exist in glassfish-web.xml. But no matter what we define there, the server always defines the file name as context-root.

Now we find the --contextroot option in the asadmin utility, which will allow us to overwrite the file name during deployment, but we would prefer to define it directly in the archive itself so that the one who deployed it at the end does not need to know the desired root end.

Is there any way to achieve this?

+5
source share
2 answers

Usually this should work with the glassfish-web.xmlfollowing:

<!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>
    <context-root>/path/to/App</context-root>
</glassfish-web-app>

But here, it looks like you need a file called sun-web.xmlfor your task.

Here is an example:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-web-app PUBLIC 
     "-//Sun Microsystems, Inc.//DTD GlassFish Application Server 3.0 Servlet 3.0//EN"   
     "http://www.sun.com/software/appserver/dtds/sun-web-app_3_0-0.dtd">
<sun-web-app error-url="">
    <context-root>/path/to/our/App</context-root>
</sun-web-app>
+4
source

In GlassFish 3 and GlassFish 4, web application configuration is done through glassfish-web.xml. In your case, the desired configuration file will look like this:

<!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>
    <context-root>/path/to/our/App</context-root>
</glassfish-web-app>

For more information, see the GlassFish Deployment Descriptor Files Oracle GlassFish Server Deployment Guide . An online version of this document can be found at http://docs.oracle.com/cd/E18930_01/html/821-2417/ .

+10
source

All Articles