Home > Ubuntu, Ubuntu Server > How to package your Tomcat webapp

How to package your Tomcat webapp

If you are a web application developer, you should want to properly make a Debian package to help installing your application in Debian and Ubuntu. This article will detail the options you have for Tomcat 6.0 webapps. It was also posted for reference (and further improvement) at https://help.ubuntu.com/community/Tomcat/PackagingWebapps. It supposes you already know the basics of Debian packaging, and how Tomcat roughly works.

Option 1: Use the system instance

The tomcat6 package provides a system-wide instance. If your webapp is relatively simple and does not require a specific configuration, you should consider packaging your webapp for deployment there. That’s what the tomcat6-examples and tomcat6-admin packages do. To benefit from webapp autodeployment, you should:

  • Depend on the tomcat6 package
  • Install your webapp into /usr/share/PACKAGENAME/WEBAPP
  • Install a deployment descriptor file into /etc/tomcat6/Catalina/localhost/WEBAPP.xml

For example, the tomcat6-examples package installs the webapp files into /usr/share/tomcat6-examples/examples, and then installs the following examples.xml file into /etc/tomcat6/Catalina/localhost :

<Context path="/examples"
 docBase="/usr/share/tomcat6-examples/examples" />
 

Your webapp should be automatically picked up by Tomcat !

Option 2: Use your own instance

Sometimes using the system-wide Tomcat 6.0 instance is just not the right solution. The most common case is when your webapp requires a very specific configuration. Rather than beating the system-wide instance into submission, by mangling the configuration file (or asking your users to do so), it’s better to set up your own instance. Tomcat 6.0 in Ubuntu and Debian provides the possibility to set up multiple instances of tomcat that share the same binaries, through the tomcat6-common package. You should then:

  • Depend on the tomcat6-common package
  • Deploy a full CATALINA_BASE directory with conf/ and webapp/ subdirectories in /usr/share/PACKNAME
  • Create an init script in /etc/init.d/PACKNAME that starts catalina.sh with CATALINA_BASE=/usr/share/PACKNAME and CATALINA_HOME=/usr/share/tomcat6
  • Have postinst create a specific user to run under, and use that in your init script
  • Create specific directories for logs and temporary files

What should the CATALINA_BASE directory look like ? Something like this:

/usr/share/PACKNAME
  conf/             <-- the configuration directory with your specific config
  logs -> /var/log/PACKNAME
  temp -> /var/cache/PACKNAME/temp
  webapps/          <-- the directory containing your webapps
  work -> /var/cache/PACKNAME/work
 

It is slightly more complex, but that way you can fine-tune your configuration without affecting any other webapp installed, since you use your own, separate, instance. Most importantly, you still get the benefit of bugfix and security updates in the common binaries.

If you need some examples, the tomcat6-user package provides a tomcat6-create-instance command that creates CATALINA_BASE directories for user instances, you can use that as a base. For the init script, /etc/init.d/tomcat6 can be used as a base.

About these ads
Categories: Ubuntu, Ubuntu Server
  1. jd
    July 29, 2010 at 14:46 | #1

    Great stuff,

    Thank you

  2. October 4, 2010 at 01:10 | #2

    Thank you so much.

    Btw any great examples of Ubuntu/Debian WAR packages?

    Thank you again
    Misha

    • Thierry Carrez
      October 7, 2010 at 10:16 | #3

      The only examples so far in the archive are the tomcat6 applications (tomcat6-examples, tomcat6-admin…).

  3. October 5, 2010 at 01:06 | #4

    Here is an example:

    http://svn.debian.org/wsvn/debian-med/trunk/packages/openmrs/trunk/#_trunk_packages_openmrs_trunk_

    How do you avoid a Pre-Depends on tomcat6 if you are installing directly into the /etc/tomcat… folders?

    Thank you
    Misha

    • Thierry Carrez
      October 7, 2010 at 10:15 | #5

      I don’t think you need tomcat6 installed and configured to add files into /etc/tomcat6/Catalina/localhost… Those files will be taken into account automatically ?

  4. August 20, 2013 at 07:39 | #7

    Thank you very much for this guide. I have found that jenkins deb package are similar to this solution and are simply to read and match with your useful hints.
    http://pkg.jenkins-ci.org/debian/

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 33 other followers