Map a war to root - JAVA Azure web role

2.2k Views Asked by At

I created a simple servlet in eclipse (as a dynamic web project) Installed the Azure SDK, Then i packaged the project for windows azure using the GUI,

I want the app to be deployed to the root folder,

So i can access it like :

mysite.com/servlet?....

and not like:

mysite.com/war_name/servlet?....

Reffering this answer : Deploying my application at the root in Tomcat

I added to my server.xml

 <Context docBase="war_name" path="" reloadable="true" />

also tried:

 <Context docBase="war_name" path="" reloadable="true" debug="0"><Context/>

I used remote control to verify that the server.xml has this line included (just before the 'Host' end tag)

And it does,

Yet i still cannot access my app as i want to.

I am new to JAVA, i am using tomcat 7, and here is a screenshot for what i have done :

enter image description here

2

There are 2 best solutions below

1
On BEST ANSWER

The simplest way to map a java webapp (eg: war) to root context path is by deleting the original tomcat_home/webapps/ROOT and renaming your war file into ROOT.war (if you're deploying in archive style), or rename your folder to ROOT (if you're deploying in exploded style). No default server.xml change is needed

Make sure the war file is placed on tomcat_home/webapps

However if you want to keep your war file name like you mentioned, ensure you delete the tomcat_home/webapps/ROOT folder to avoid confusion

This answer has more information about mapping tomcat root context path: https://stackoverflow.com/a/5328636/179630

0
On

I'm adding this as an answer since it contains code, but it's mostly an expansion on gerrytan's answer.

If you're using the Azure Eclipse plugin, you can edit package.xml in the Azure deployment project so eclipse will build your war automatically and rename it to ROOT.war before placing it in the deployment project.

Near the end of package.xml, you should have a line like this:

<component cloudmethod="copy" cloudsrc="auto" cloudupload="always" deploydir="%SERVER_APPS_LOCATION%" deploymethod="copy" importas="<my_app.war>" importmethod="auto" importsrc="<path to my_app project>" type="server.app"/>

(It should be within the workerrole tag)

In this line, replace "" with "ROOT.war" so it looks like this:

<component cloudmethod="copy" cloudsrc="auto" cloudupload="always" deploydir="%SERVER_APPS_LOCATION%" deploymethod="copy" importas="ROOT.war" importmethod="auto" importsrc="<path to my_app project>" type="server.app"/>

and delete the old my_app.war from deployment. When you deploy next time, you app will be deployed as ROOT. And as gerrytan said, make sure you delete the /webapps/ROOT folder in tomcat beforehand.

EDIT:

Another caveat - If your application includes a .gitignore file (or a similar dot file/directory like .svn), add <defaultexcludes remove="**/.gitignore"/> to package.xml under the windowsazurepackage taskdef.

Without this, the Azure plugin (that uses Ant) doesn't delete .gitignore files between Azure deployments. This means that the application's folder in the webapp folder stays when everything else is deleted. When Azure is re-deployed, tomcat doesn't re-deploy the application because it sees that the application's folder is there.