With Glassfish you also have the choice of URL/path location for your web app but setting up Glassfish web application at root URL is a bit different than you do it in Tomcat (ROOT.war, server.xml).
Download a hello-glassfish.war sample application and save it in your home directory. You can use it for testing. It already has context-root set to '/' in WEB-INF/glassfish-web.xml
.
If your app DOES NOT have context-root set in glassfish-web.xml
you can run
asadmin --port=YOUR_CUSTOM_PORT deploy --contextroot "/" hello-glassfish.war
or
use web-based Admin Console to deploy the application with a "/" web context (by setting the "Context Root:" field to "/").
If your web application HAS context-root set in glassfish-web.xml (like the hello-glassfish.war) you can: run
asadmin --port=YOUR_CUSTOM_PORT deploy hello-glassfish.war
or login to web-based Admin Console and deploy the application with a "/" web context (by setting the "Context Root:" field to "/"). Here you may expect that you do not need to enter the context but if you do not enter it, the WAR name will be used by default and the context-root from your glassfish-web.xml
will be ignored. Third alternative is to copy it into autodeploy directory for example
cp ~/hello-glassfish.war ~/appservers/glassfish-4.0/glassfish/domains/domain1/autodeploy
Example glassfish-web.xml
specifying context-root:
<?xml version="1.0" encoding="UTF-8"?>
<!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>/</context-root>
</glassfish-web-app>
Deployments made with Ant and Maven will also honor context-root setting in glassfish-web.xml
.
If you see Context path from ServletContext: differs from path from bundle: /]]
warning in Glassfish log you can remove '/' from glassfish-web.xml
but it is non-harmful.
The above hints will also apply to EAR packaged web applications with application.xml
.