Tomcat 7 comes with a lot of new features, like Servlet 3.0 specification, filter for preventing CSRF attacks, and more and more features. One feature that I really like is the simplicity that has acquired embedding a Tomcat into an application.
First of all you are not required to download all archives; there is a separated link for downloading only required jars
Second one is how easy is to create a tomcat instance and add the directory where web application is deployed.
String webApp = ...;
String tomcatDir = ...;
Tomcat tomcat = new Tomcat();
Only three sections:
- Configure Tomcat. The base directory for temp files.
- Adding information about where web application is deployed and which context path should serve it.
- Starting server and waits until application is closed.
I have not found in Tomcat documentation something like Jetty that you can set a War file and container is the responsible for unpacking it. I think that in case of Tomcat some actions should be taken by developer for unpacking it.
I am not going to discuss about what embedded server is better, if Jetty or Tomcat, each one have their features, and their advantages and disadvantages, this post is only written as a resource for teaching how to embed tomcat into an application.