NR Time - Powerful time tracker for Mac OS X

Feel the ease of time tracking with NR Time. Log your time expenses in the billing-friendly format with minimal effort.

Packaging Java applications for Ubuntu and other Debian’s

Posted: August 31st, 2005 | Filed under: Linux, Programming | 2 Comments »

As all of you probably know, we are building the BlogBridge application – the next generation of feed aggregators. At the present moment we are distributing the application in two forms: as Java Web Start application and ZIP-packaged Java application available for download from SourceForge.net. Lately, we started to think how to create native installation/uninstallation experience for our users on different platforms. We decided to support native installations for Windows, Mac OS X, generic Tar.GZ archives and Debian packages.

In this tutorial I will share the basics of Debian package creation for Java applications.

Debian GNU/Linux Bible
by Steve Hunger
Linux for Non-Geeks
by Rickford Grant

So where do we start? We start from understanding the rules of placing application requisites on the user’s filesystem. Typical Java application has main JAR, number of libraries in form of third-party JAR’s, icon file and shell script to start the application itself. As all Unix/Linux users know, executable applications always reside in

/bin

and

/usr/bin

folders, libraries are in

/lib

and

/usr/lib

and icons are in the application folder inside the

/usr/share/doc

folder. The placement rules tell that it’s better to use the directories under

/usr

for user-space applications. So, here is what we end up with:

/usr/bin/myapp.sh
/usr/lib/myapp/myapp.jar
/usr/lib/myapp/hsqldb.jar
/usr/share/doc/myapp/icon.gif

At this moment we have our deployment structure ready for packaging into DEB package, but wait a second… We will need at least DEB package control descriptor to let the user know what this application is about.

Let’s create a very simple descriptor:

Package: myapp
Version: _version_
Section: web
Priority: optional
Architecture: all
Maintainer: Aleksey Gureev 
Description: my first sample application which isn't
 doing anything special.
 .
 And other description goes
 here too.
 .

Please note that each line of Description starts with space (or

dpkg

will interpret first word of it as a field) and empty lines have dot.

This descriptor tells package management applications all information necessary to describe the package contents to the user. Put this descriptor into the file named “control”.

The next step is to create the directory structure for dpkg application to convert into DEB package. Build the directory structure below somewhere in the temp folder:

debian/DEBIAN
debian/usr/bin
debian/usr/lib/myapp
debian/usr/share/doc/myapp

Now populate the directories as we defined above and put “control” file into DEBIAN directory. The last step is to issue proper

dpkg

command. Here it is:

dpkg --build debian

It will produce “debian.deb” which can be renamed into something more meaningful, like “myapp-1.0.deb”.

Now your Java application is ready for installation on Debian systems like any other native application! Was it simple?

Though, I did another additional step to make things even more perfect – I managed to add the application to the Gnome Applications menu. It appeared to be very easy and installation started to look really professional. In order to add the item to the menu of Gnome you need small descriptor which should be added to

/usr/share/doc/applications

directory during installation. Here’s sample descriptor for Internet application:

[Desktop Entry]
Encoding=UTF-8
Name=My Application
Comment=My First Application
Exec=/usr/bin/myapp.sh
Icon=/usr/share/myapp/icon.gif
Terminal=false
Type=Application
Categories=GNOME;Application;Network
StartupNotify=true

This descriptor file should be named “myapp.desktop”. Of course, only the extension is mandatory and main name can be different. The last stroke is to add corresponding directory and this descriptor to the package source hierarchy and rebuild DEB package. Have a practice!

To be absolutely sure that you don’t violate any good package’s rules you can use very convenient application “lintian”. It will analyze the package you’ve just created and outline all violations. You can feed the output log from “lintian” to “lintian-info” to get very detailed explanations of your package problems with references to source standards documents. Pure power on the fingertips!

That’s all for now. In my future plan to learn how to install KDE menu items. Maybe something else – not sure yet.

Package it!


2 Comments

  1. 1 miss tress said at 18:17 on October 18th, 2006:

    heyas all.
    my 40 gig drive is going to good use now. I have installed UBUNTU and have ordered KUBUNTU.
    I dont know how to install the driver for my ati radeon 9600xt.
    Actually i dont know if i am meant to be downloading and installing XFREE86 or the XORG version of the driver. I am downloading them both but i dont know how to do anything in Linux really.
    I dont know where I am meant to set up my modem or set up a net account. (no INETWIZ.EXE)
    So yeah, can someone help me out with getting my ATI driver installed?
    and does anyone know of a good long PDF file i can read and wrap my brain around.
    I’m still a Windows user, but I want to use Linux as much as possible.
    Thanks. :)

  2. 2 Aleksey Gureev said at 07:31 on October 19th, 2006:

    Why do you need to install ATI driver? Doesn’t the one coming with the distribution work?

    Usually, the network is being setup during the installation and it’s hard to believe that you missed the phase. But it’s not a big deal; you can tune or re-tune it easily: see System -> Administration -> Networking. Check this link for more info: http://ubuntuguide.org/wiki/Dapper#How_to_configure_network_connections

    They also have tons of tips and documentation in their support wikis and forums. Just check the bookmarks of your Firefox, they put everything there for newbies to find easily.

    The page above full of essential information to help you get started. I personally use Ubuntu since the early ages and it proved to be reliable and, what’s no less important, repeling viruses and trojan horses. That’s crucial these days.

    Hope that helps!


Leave a Reply