Suppose you have built a Java web application as a Java servlet. Now you want to create .deb Debian package for the Java web application, such that when you install the .deb package file, it will automatically install any prerequisite packages (e.g., Java and Tomcat web server), and deploy the Java servlet on Tomcat.
I assume that you already built and exported a Java servlet into .war file. Then the Debian package will simply consist of .war blob file, and any dependency information. Here is guide on how to create .deb package from .war file.
First, install any necessary packages to build a Debian package.
Create a directory for your application.
Copy your .war application file to the directory.
$ cd myapp-0.1
Create skeleton files needed for packaging.
Maintainer name : My Name Email-Address : my_email@unknown Date : Tue, 02 Apr 2013 11:33:28 -0400 Package Name : myapp Version : 0.1 License : blank Type of Package : Independent Hit
Once you hit <enter>, it will create several skeleton files in myapp-0.1/debian/
Since you are packaging a pre-built .war file, you don't need any build process within packaging rules. Remove any reference to "makefile" from debian/rules.
$ mv debian/rules.temp debian/rules
The next step is to modify debian/install. Here you specify a list of files to install, as well as their respective installation directories. In our example, files to install correspond to .war file, and installation directory is the webapps directory of Tomcat. Assuming that .war file was built for Tomcat7 web server, you modify debian/install as follows.
Modify debian/source/format as we will not be building a quilt based package.
Remove unnecessary example files.
Modify control information of your package. Importantly, you need to specify tomcat7 as dependent package (in "Depends:" field). You don't need to specify Java as dependent since Java dependency is implicitly implied by adding tomcat7 which in turn depends on Java.
Source: myapp Section: unknown Priority: extra Maintainer: My Name
Build-Depends: debhelper (>= 8.0.0) Standards-Version: 3.9.3 Homepage: #Vcs-Git: git://git.debian.org/collab-maint/indoornav.git #Vcs-Browser: http://git.debian.org/?p=collab-maint/indoornav.git;a=summary Package: myapp Architecture: all Depends: tomcat7 Description: This is my web application. This is a long description of my web application.
Finally, build the package.
After building is completed, you will have .deb file generated in the parent directory.
Subscribe to Xmodulo
Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.
Did you find this tutorial helpful? Then please be generous and support Xmodulo!