I’ve been bashing my head against THIS one for weeks, on and off. Each time I tried to figure out how to map my app to the name of my choice (‘/’) nothing I did seemed to work!
Finally today I learned about yet another XML file you have to edit in Java EE – application.xml. Yep, the Java EE development life is filled with wonderful and magical XML files.
Application.xml is a lot like web.xml, but it applies to the EAR. What isn’t obvious, and which nobody warned me about, is that the context-root for an app is set in application.xml, and it doesn’t matter what you put into sun-web.xml, web.xml, or anything else to try and rename the context-root of your war. application.xml will override all of that.
So, I’m happy to have found it, but sad that it took so long. Hopefully others having the same problem – “context-root in sun-web.xml ignored” or “glassfish ignores my context-root” for those searchers out there – can find this post and be enlightened by it!

February 1, 2008 at 6:11 am |
Thanks for sharing this.
February 25, 2008 at 7:56 pm |
Thanks for sharing this information. Like you, I also spent quite some time trying to achieve this supposedly easy task.
April 25, 2008 at 12:26 pm |
Dobes,
This was just what I needed. I also did not quite figure out what happend.
Thank your for sharing this!
May 16, 2008 at 3:36 am |
Thanks, had are hard time looking into this.
July 7, 2008 at 7:46 pm |
The GlassFish server has a server GUI manager available at localhost port 4848 through the browser.
One can log in (default username/password are “admin” and “adminadmin” respectively), go to Applications->WebApplications, click on the name of your one and you’ll see to the right the Context Root option which you can change and click “Save” and you’re done.
July 7, 2008 at 10:16 pm |
Thanks xlinuks – that’ll help for a a WAR file (a Web Application), but this tip is for people who’ve created an EAR file (an Enterprise Application). In the version of glassfish I have, I can’t change the context root of a WAR file that’s bundled inside an EAR file using the admin interface, although I can, as you’ve shown, change the context root of a WAR file.
FWIW, anyone who didn’t know already, you CAN change the context root of a WAR file by editing it’s web.xml or sun-web.xml, as long as it’s not being deployed as part of an EAR file.
September 24, 2008 at 7:23 am |
FWIW, if you’re using NetBeans and create the EAR in there, you can then right-click on the EAR icon in the project view (triangle icon in NB), select New…, and choose “Standard Deployment Descriptor…”.
This will cause NetBeans to create and populate the application.xml file, including referencing the EAR’s source war files and putting in your already-defined context roots.
September 24, 2008 at 8:58 am |
@Greg – thanks for the tip. I’m not a NetBeans user but they may find that useful!
October 28, 2008 at 5:25 am |
Thanks for the NetBeans tip!
December 8, 2008 at 12:40 pm |
Thanx!
I was also baffled there for a while.
December 25, 2008 at 12:45 pm |
Dobes, thanks a lot for this information. I am new to glassfish and I am currently having sleepless nights over trying to render a jsf page, packaged in a war file, which in turn is in a ear file. The ear is successfully deployed in glassfish hotdeploy directory but when I try to render it by typing:
http://localhost:8080//pages/new.jspx,
In the server.log, I see:
…File “$com.sun.aas.instanceRoot}/applications/glassfish/domains/domain1/docroot//pages/new.jspx” not found|#]
Do you know why it is looking in docroot? I have google and found a few questions raise on the same issue but no answer (I wonder why). Any hint would be enormous help. And thanks in
advance.
Guest.
December 25, 2008 at 2:58 pm |
Hello “Guest”, if that’s REALLY your name!
I haven’t run into this problem myself, but it seems suspcious that you have two slashes before pages. What is the name of your war file? Have you tried accessing it using that name?
Good luck …
December 25, 2008 at 11:17 pm |
Dobes, thanks for your response.
>>you have two slashes before
I had the context-root name (or place holder inside < and >) between the two slashes, which the page did not render.
>>What is the name of your war file?
The name of the war file is ‘foo-web.war’ and the ear is ‘foo.ear’. But I am deploying the foo.ear containing the web.war. And I have my context-root set to ‘/foo-web’–formerly in the ’sun-web.xml’ and ’sun-application.xml’ and now (albeit unnecessary) in the ‘application.xml’ .
>>Have you tried accessing it using that name?
Yes I have tried foo, foo-web, i.e., the name of the war with no success.
Glassfish deployment instruction says:
1 deploy [ear, war]to autodeploy dir. and then do:
2. http://localhost:8080/foo-web/pages/new.jspx.
Is there something I am missing between steps 1 and 2?
Thanks again for you help.
December 25, 2008 at 11:39 pm |
Those instructions sound fine to me – maybe you can check in the logs or the admin web interface to see if it has been deployed or not, and if there were errors during deployment. It can also help to browse around in the domains/domain1/applications/j2ee-apps and see what the folder structure there is. I don’t think I have time to really dig deep into this one … it’s probably something very simple once you figure it out.
Have you tried just deploying something simple, like a WAR file, or something someone else has already made?
December 26, 2008 at 12:40 am |
>> I don’t think I have time to really dig deep into this one
Thanks for your response, but as I said in my first post, I am able to deploy foo.ear sucessfully—server.log, verifier-result’s foonnnnnnn.txt, and console, didn’t record any failures, warnings or errors.
Once again, thank you.
January 17, 2009 at 11:36 am |
Thanks for the post, This simple problems are the ones that drive someone crazy.
February 23, 2009 at 4:02 am |
Thanks for help
April 15, 2009 at 4:07 pm |
I just started with ee application. I by mistake deleted a web project that i was experimenting with. now the glass fish gives the following error.
The context root [EJBTrials-war] in application [EJBTrials-war] is already in use by another application on this instance [server].
Can i change the context root element and solve my problem? If so how?
Thanks in advance.
April 15, 2009 at 5:22 pm |
Hi psm,
Sadly, I don’t know the answer to your question – try the glassfish mailing lists or forums!
September 25, 2009 at 6:23 am |
Thanks for this. I was pulling my hair out looking for the solution to this one.
November 7, 2009 at 8:40 am |
thanx for this small tutorial, works perfectly