Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy apps in tomcat server

Tags:

tomcat

tomcat8

I want to deploy myapp in tomcat server. I know one way is to delete the Root folder from webapps and rename my app.war as ROOT.WAR. But i do not want to do this. I want to deploy like when user access my app as www.xxx.com , it should go to my app like www.xxx.com/login.html. Please help

like image 571
Shankar Kumar Avatar asked Dec 21 '16 12:12

Shankar Kumar


2 Answers

You can deploy any WAR file (or exploded WAR directory) from (almost) anywhere with any context name you want, as long as it doesn't conflict with any auto-deployed application. Here's how:

  1. Remove any conflicting applications from webapps/ (in this case, really, it's just ROOT)

  2. Move your own application someplace other than in webapps/

  3. Copy the META-INF/context.xml file from your application and place it into Tomcat's conf/[engine]/[host]/[contextpath].xml – for example conf/Catalina/localhost/ROOT.xml

  4. Edit conf/[engine]/[host]/[contextpath].xml and add this attribute to the <Context> element:

    docBase="/path/to/your/WAR.war"

Now, Tomcat will deploy /path/to/your/WAR.war on context path / (because the deployment descriptor's filename is ROOT), and you didn't have to modify conf/server.xml.

Who cares about modifying conf/server.xml? Well, that file is only read once during container startup, so if you want to make changes, undeploy, redeploy, etc. you must restart the entire container to pick-up those changes. It's much better to use Tomcat's auto-deployment facility, which as you can see is quite flexible.

All of this is laid out in Tomcat's documentation on defining contexts where, incidentally, the very first sentence makes it clear that defining a context in server.xml is a bad practice.

like image 146
Christopher Schultz Avatar answered Nov 15 '22 10:11

Christopher Schultz


You have several options to set a root application. (see https://stackoverflow.com/a/5328636/6371459)

  1. Remove ROOT directory and deploy your war as ROOT.war

  2. Deploy your war in webapps and configure the context root in conf/server.xml to use your war file (not recommended because requires restarting)

  3. Create a specific context file $CATALINA_BASE/conf/[enginename]/[hostname]/ROOT.xml and set docBase=your_war_name like previous 2) (see @ChristopherShultz answer)

Since you have discarded option 1, and option 2 is not recommended, I suggest use a context file

like image 42
pedrofb Avatar answered Nov 15 '22 10:11

pedrofb