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.

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

<metaxmlns="http://exist-db.org/xquery/repo"><description>My eXist application</description><author>Dan McCreary</author><website>http://danmccreary.com</website><status>alpha</status><license>GNU-LGPL</license><copyright>true</copyright><!-- set this to "application" (without quotes) for system that have a GUI --><type>application</type><target>myapp</target><prepare>pre-install.xql</prepare><finish>post-install.xql</finish><permissionsuser="admin"password=""group="dba"mode="rw-rw-r--"/><!-- this element is automatically added by the deployment tool --><deployed>2012-11-28T23:15:39.646+01:00</deployed></meta>

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

verify that repo.xml and expath-package.xml exist in the source dir and copy them into temp.dir

copy all application files temp.dir

create zip file from contents of temp.dir in the packages area and upload it to repositories if needed

<targetname="generate-app-xar"description="Generate Application xar archive file"><echo>Making Package for ${app-name} use source from ${source-dir}</echo><zipdestfile="${package-dir}/${app-name}-${app-version}.xar"><filesetdir="${source-dir}"><includename="**/*.*"/><excludename="**/.svn"/></fileset></zip><echo>Package is stored at ${package-dir}/${app-name}-${app-version}.xar</echo></target>

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

<targetname="generate-xar"description="Generate xar archive"><echo>Making ${ant.project.name}.xar...</echo><!-- run a transform in the input specification file to create the a.xml file --><xsltforce="true"style="${xslt.dir}/generate-xar-descriptors.xsl"in="${web.specs.dir}/${ant.project.name}/${ant.project.name}.xml"out="${temp.dir}/files/a.xml"><paramname="module-version"expression="${module-version}"/><paramname="eXist-main-class-name"expression="${eXist-main-class-name}"/></xslt><deletefile="${temp.dir}/files/a.xml"/><!-- now create the .xar file with all our files in the right place --><zipdestfile="${temp.dir}/archives/${ant.project.name}-${module-version}.xar"><filesetdir="${temp.dir}/files"><includename="**/*.*"/><excludename="*-tests.jar"/></fileset></zip></target>