Using the context-root from glassfish-web.xml in GlassFish 3
Asked Answered
F

2

5

We recently switched to Glassfish 3.1.2.2 and have several Web-Applications packaged as war files. At times the desired context-root for these applications differs from the filename.

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

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

We noticed that the same Tag exists in the glassfish-web.xml. But no matter what we define there, the server always determines the filename as the context-root.

Now we find the option --contextroot in the asadmin utility that would allow us to overwrite the filename at deploy time, but we'd prefer to do define it directly in the archive itself so that whoever will deploy it in the end won't need to know the desired contex-root.

Is there any way to achieve this?

Forbis answered 25/4, 2013 at 13:39 Comment(0)
A
4

Normally this should work with a glassfish-web.xml looking 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/App</context-root>
</glassfish-web-app>

But here it looks like you need a file called sun-web.xml for 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>
Aeroballistics answered 25/4, 2013 at 15:34 Comment(3)
That's strange (and somewhat embarassing) we did have that tag set (although in glassfish-web.xml since the file has been renamed in GF 3.1) but without noticing we overrode it in our maven config where the filename was explicitly passed as context-root, overriding the definition in the glassfish-web.xml. You are, of course, correct :)Forbis
It did not worked for me with glassfish 3.1.2.2 using java ee war deployment even if I configured both the glassfish-web.xml and sun-web.xml as well. Only tha asadmin deploy parameter --contextroot=/ helped. But I am looking forward to find the right configurtion for this topic.Robespierre
I did some more experiments and finally the solution was to modify the glassfish-web.xml only. If I add the context-root parameter only to the glassfish-web.xml and not the sun-web.xml the result was the expected one.Robespierre
F
10

In GlassFish 3 and GlassFish 4 the configuration of a web application is done via glassfish-web.xml. In your case the desired configuration file would 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>

You can find further details in section GlassFish Server Deployment Descriptor Files of Oracle GlassFish Server Application Deployment Guide. A online version of this document can be found at http://docs.oracle.com/cd/E18930_01/html/821-2417/.

Fullback answered 21/8, 2013 at 13:22 Comment(1)
Yes, I had a similar issue. The sun-web.xml has no effect on the context root. I changed to use the glassfish-web.xml. It works.Astraea
A
4

Normally this should work with a glassfish-web.xml looking 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/App</context-root>
</glassfish-web-app>

But here it looks like you need a file called sun-web.xml for 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>
Aeroballistics answered 25/4, 2013 at 15:34 Comment(3)
That's strange (and somewhat embarassing) we did have that tag set (although in glassfish-web.xml since the file has been renamed in GF 3.1) but without noticing we overrode it in our maven config where the filename was explicitly passed as context-root, overriding the definition in the glassfish-web.xml. You are, of course, correct :)Forbis
It did not worked for me with glassfish 3.1.2.2 using java ee war deployment even if I configured both the glassfish-web.xml and sun-web.xml as well. Only tha asadmin deploy parameter --contextroot=/ helped. But I am looking forward to find the right configurtion for this topic.Robespierre
I did some more experiments and finally the solution was to modify the glassfish-web.xml only. If I add the context-root parameter only to the glassfish-web.xml and not the sun-web.xml the result was the expected one.Robespierre

© 2022 - 2024 — McMap. All rights reserved.