How to change context root of URL --> Rename WAR file

After many hours of research over many days, I have found an utterly simple way to change the URL used to access a Vaadin app:



Rename the WAR file

Example:
• Domain is "
acme.com
"
• Vaadin app name is "
AcmeInvoices
"

When use Eclipse Indigo feature to export (
File > Export > Web > WAR file)
, I use the default name. In this case, "
AcmeInvoices.war
".

I move that war file to Tomcat 7, start Tomcat, and Tomcat auto-deploys the app including expanding the war file back to a folder.

Then I can reach the app using this URL:

http://www.acme.com/AcmeInvoices

But what if I want a simpler URL such as this:

http://www.acme.com/invoices

To make that my URL:
[1]
On my deployment server, shutdown Tomcat.
[2]
Delete the folder expanded from the WAR file.
[3]
Rename the "
AcmeInvoices.war
" file to "
invoices.war
".
[4]
Start Tomcat, letting it auto-deploy the app.
[5]
Note the newly created folder "
invoices
".
[6]
Test the app using the new URL,
http://www.acme.com/invoices/

Similarly, if you want the URL:

http://www.acme.com/app/

…just rename your
AcmeInvoices.war
file to "
app.war
" when deploying.

At first thought, this seemed so simple and easy that I suspected that I must be “cheating”. But on second thought, this seems perfectly legitimate. Is it?

–Basil Bourque

Yes, It’s perfectly legitimate if you are allowing Tomcat to automatically deploy your webapplications.

You can also explicitly configure tomcat (via XML configuration) to deploy a war/directory to any context name you like.

The choice is yours.

What Charles says is correct: the context root equals the war file name unless you do something to change it.

With many application servers (and there’s probably some way to do this with Tomcat as well), you can also set the context root at deployment time. For instance, a GlassFish deployment like this:

…will deploy the application at http://example.com/foo instead of http://example.com/bar. If you’re only ever running one application on a server, then you could also deploy it to / so that the URL is simply http://example.com with no other information.

Cheers,
Bobby