Application Package Manager with Ant and Java

Let's build a simple but powerful application package manager with Ant.

Everyone knows the operation systems package manager like dpkg (from Debian) or RPM Package Manager (from RedHat).

Sometimes there is a need of such a management system in our own use.

The environment doesn't have to be an operation system, but for instance a web server or just a container application.

The manager must be able to manage package dependencies, versions and installation to the environment system.

All the information must be contained only inside the application itself, the system nor the manage must not have any additional data about a concrete package.

To distinguish between a package and a package manager we will use in our context terms Application Package (AP) and Application Package Manager (APM).

Scenario One: Container Application

We want to develop a container application which on the starup checks the application folder and install included application if not installed yet.

Consider an application which simulates an operation system. It has a core, folder for configuration, run and so one. In the simplest case:


The file conf/applications.conf contains pairs of application-name=files-in-bin-directory-comma-separated. It's empty with a brand new system installation or contains some initial system-provided application and files.

The system calls the APM (core/apm.xml) after the start.bat script is executed. The APM takes care of the applications installation. Then a system program (from the library core/lib/system.jar) goes thru the conf/application.conf and run each application logic (in our case only prints the content of a file defined by the application).

The applications directory stands outside the system directory, it means even when the system is completely updated remains the applications directory untouched and the included application are always ready for a new installation by the next startup.

AP Implementation

An AP is nothing more than a folder with a strict defined structure containing all the needed system-related information about itselft. We will put all the AP-related files into the META-INF sub-folder.

Every AP must have a meta information file. We will create a ordinary property file and call it The meta information file contains the name, version and dependencies (optionally) of the AP.

For our example we need data to be executed (their content will be printed after the system start). We will put them into data folder. 


For an application to be deployed must be the application folder named in the pattern name-version (e.g. code>MySuperAppA-1.0) and placed in the applications folder. This is the default place for the APM to look for the new APs.

Demo APs 

For the test purposes let's create three APs: A, B, C with the following dependencies:

A --> B, C
B --> C
C --> (no dependency)

Each AP has two text files called be the pattern ap-name-1.txt and ap-name-2.txt with the content of the name of the AP and number of the data file.

For example the AP named B contains in the folder META-INF/data a file B-1.txt with the content "B1" and a file B-2.txt with the content "B2".

After start of the demo system, we should see the following output:


The order of the startups follows the dependencies definitions of the APs.

APM Implementation

First of all we need two Ant task for our APM script. The implementation of both is in the core/lib/apm.jar Java library and could be found in the source codes under the ant-lib project.

Dependencies order

This task takes a path as a parameter, goes thru this directory and gets all the folders inside it as an input.

Then goes thru all of them and checks the dependencies from the META-INF/ So it creates a list of dependencies in the order of the need. For each application in the list a sequence inside the task will be executed. The sequence defines the installation procedure.

<taskdef name="dependencies-order" classname="cz.net21.ttulka.apm.ant.demo.DependenciesOrderTask"
         classpath="core/lib/apm.jar" />
<dependencies-order path="../applications" relpathmetainfofile="META-INF/">
        <antcall target="install-app">
            <param name="appPath" value="@{application}" />

Configuration record 

For every application we need to scan the data folder and create a list of the files inside. This list in comma-separated form will be appended into the applications configuration file.

<taskdef name="create-conf-record" classname="cz.net21.ttulka.apm.ant.demo.CreateConfRecordTask"
         classpath="core/lib/apm.jar" />
<create-conf-record path="${appPath}/META-INF/data">
        <antcall target="write-conf-record">
            <param name="record" value="@{record}" />
<target name="write-conf-record">
    <echo file="conf/applications.conf" append="true">${line.separator}${appName}=${record}</echo>

Scenario Two: Application (Web) Server 

Such a APM could be used in the same way in the case of installing web applications into a server

Consider that the applications provide some functional services and their installation is dependent on one or more other.

We can also install more versions of an application and enable only the latest version.

For a proper run of an application the server needs to be configurated in a way known only to the application self.

Application must be corretly re-installed after an update of the server, even when the old server data was completely removed.

Even here helps the APM in all the above mentioned cases. 


You can download the source project and addapt it to your needs and desires.