Apache Ant/Creating a .xar file

Motivation
This example is under development!

You want to create an XML archive file (.xar file) directly from your source code that can be used to load library modules or applications into a native XML database. This makes it much easier for users to install your module or application. The packaging process does all the work of uploading your files into the correct location on a running eXist server and also sets all the permissions of the XQuery files (.xq) for you automatically.

Method
We need to create a "zip" file with all the right components in it.

The format of the package is here:

http://expath.org/spec/pkg

The eXist-specific package documentation is here:

http://demo.exist-db.org/exist/apps/doc/repo.xml

GUI Package vs. On-Disk Library vs. In DB Library
There are three types of installation packages:
 * 1) A external library that is not in the database
 * 2) A library that is loaded into the database
 * 3) A full application with a GUI

For all library apps without GUI but deployed into db you must use two attributes, one for the target the type="library" use the following structure: target="some /db path" + type="library"

For a simple XQuery library package, which only needs to be registered with eXist but not deployed within the exist database the target attribute should not be used. no target + type="library"

Sample Package Structure
The archive must contain two XML descriptor files in the root directory: expath-pkg.xml and repo.xml

Sample expath-pkg.xml file

Note that the file name and the string in the namespace are "pkg" but the element name and the attribute in the dependency are "package". Make sure to keep these clear.

The format of this XML file is describe in the EXPath documentation.

Sample repo.xml file that contains instructions for the eXist-specific packaging

Sample Apache Ant Target to Generate an Application .xar file
This ant target needs the following inputs:

source-dir - the place you keep your source code package-dir - a temp dir such as /tmp/my-package to store temporary files app-name - the name of your application app-version - the version of your application


 * 1) verify that repo.xml and expath-package.xml exist in the source dir and copy them into temp.dir
 * 2) copy all application files temp.dir
 * 3) create zip file from contents of temp.dir in the packages area and upload it to repositories if needed

Sample Apache Ant Target to Generate a Library .xar file
This script depends on the following Ant properties:

ant.project.name - the name of the project xslt.dir - the directory that the XSLT script are stored temp.dir - a temp dir such as /tmp to store temporary files web.specs.dir - the place to put the results

Acknowledgements
The Apache Ant target and the XSLT script were provided by Claudius Teodorescu.