Saturday, February 18, 2012

Swing applications deployment on Linux: DEB packages

Deploying Java Swing applications on Linux could be a pain, mostly due to differences in distributions, desktop environments and package management. Two of the most widely used package management systems are DEB and RPM. In today's post, I'm gonna try to create .DEB package for my sample Swing application.

DEB packages are created using dpkg-deb tool, found in most Linux distributions. We need to create correct file structure and control file which is used by dpkg-deb to create the package. The following image shows the file structure:
Directory structure for DEB packages

Top-level directory (myapp-1.0.0) is used as a root for package creation. By default, created package will be named myapp-1.0.0.deb. This can be overriden at runtime.

Directory DEBIAN has a special function. It contains a control file (control) which controls package configuration. Script postinst is run after installation, and is used for post-install configuration, or any required package initialization.

Other directories only reflect application structure as it will be laid out on user's hard drive. Application will be installed in /usr/loca/myapp, and desktop shortcut will be placed in /usr/share/applications. Application consists only of a single JAR file, a shell script that starts it and an PNG image that will be used as a shortcut icon.

Now is the time to get busy. Control file is the central point of this example, and this is what it looks like:

Package: myapp
Version: 1.0.0
Section: Java
Priority: optional
Architecture: i386
Depends: openjdk-6-jre
Maintainer: John Doe 
Description: Sample application

  • Package - package name as it will appear in OS
  • Version - package version
  • Section - software management section ini which package will appear
  • Architecture - target machine architecture (i386 or amd64)
  • Depends - list of packages required to saticfy dependencies, here it is only JRE. Please note that Java packages can be different between distributions
The rest of entries are not that important for this case, so I will just skip them. Now that I have everything in place, it is time to build a package. Go to top-level directory (same level as myapp-1.0.0 directory), and run the following command:

dpkg-deb -- build myapp-1.0.0

 This will build package myapp-1.0.0.deb in current directory. I order to install the package, run the following command:

dpkg -i myapp-1.0.0.deb

Now, the package is installed as any other DEB package on user's machine. The following screenshot shows Ubuntu GNOME menu with our application installed.

That's about all the work required to build Debian packages for Java Swing applications. As usual, entire source code and some useful links are shown here.


  1. Awesome, This is really neat. Thanks for nice article and source code it helps.

    Is there anyway we can specify a custom icon for our application?

  2. Very informative feature indeed, i have come across a similar solution at an ERP Job Board