31 December 2010

If you search “embedded tomcat” in google, you will get a bunch of instructions how to do this, but non of them mentioned how to enable hot deploy.

1
2
3
4
5
6
Embedded embedded = new Embedded();
 
// create engine, host, connector, context
...
 
embedded.start();

The above code will not enable hot deploy by default. So what we need to do is adding a LifeCycleListener to the host we create.

1
2
3
4
5
6
7
8
9
10
11
12
Embedded embedded = new Embedded();
 
...
 
StandardHost host = (StandardHost) embedded.createHost("localhost",
        getHome() + "/webapps");
host.setAutoDeploy(true);
host.setDeployOnStartup(true);
host.addLifecycleListener(new HostConfig());
 
...
embedded.start();

And the following things are the same as the stand alone Tomcat: define “.xml” and put war files or directory to “/webapps”.

One more thing about how to deploy the default web app:

  • use ROOT.xml, and ROOT.war
  • or use ROOT.xml and define “docBase” pointing to the war file or directory which should not be under “appBase”, and you can name the war or directory anything you like; if symbolic link is used and the original war file or directory get modified, your web app will also be redeployed


blog comments powered by Disqus