Apache Ant/存储 XML 数据
外观
您想将文件或文件层次结构上传到 eXist。
我们将使用 xdb:store 函数,并演示如何使用其选项加载子文件夹。
每个构建文件必须有四个关键组件
- 对硬盘驱动器上内部文件的引用(理想情况下在属性文件中)
- 您 Ant eXist 扩展的 typedef
- 一条路径告诉它从哪里获取 jar 文件
- 一个目标来执行加载
<project xmlns:xdb="http://exist-db.org/ant" default="upload-collection-to-exist">
<!-- This is where I put my copy of the eXist trunk code -->
<!-- It is the result of a subversion checkout from https://exist.svn.sourceforge.net/svnroot/exist/trunk -->
<property name="exist-home" value="C:\ws\exist-trunk"/>
<!-- this tells us where to find the key jar files relative to the ${exist-home} property -->
<path id="classpath.core">
<fileset dir="${exist-home}/lib/core">
<include name="*.jar"/>
</fileset>
<pathelement path="${exist-home}/exist.jar"/>
<pathelement path="${exist-home}/exist-optional.jar"/>
</path>
<typedef resource="org/exist/ant/antlib.xml" uri="http://exist-db.org/ant">
<classpath refid="classpath.core"/>
</typedef>
<target name="upload-collection-to-exist">
<echo message="Loading Documents to eXist."/>
<xdb:store
uri="xmldb:exist://127.0.0.1:8080/xmlrpc/db/my-project"
createcollection="true"
createsubcollections="true"
user="admin" password="">
<fileset dir="C:\ws\my-project\trunk\db\my-project">
<include name="**/*.*"/>
</fileset>
</xdb:store>
</target>
</project>
如果您只使用一组本地文件,上面的脚本将正常工作。但是,如果您有多个用户,每个用户可能将本地文件放在不同的位置。如果是这种情况,您需要将所有本地文件引用隔离到一个名为 local.properties 的文件中。
以下示例来自 eXist 文档项目,用于在端口 8080 上运行的服务器,上下文设置为“/”
# Local Property file for eXist documentation project
#
# this file is loaded into the build.xml file using the <property file="local.properties"/>
# it contains any local references to your
# Properties on a Windows system
exist-home=C:\\ws\\exist-trunk
exist-docs=C:\\ws\\exist-docs
user=admin
password=
uri=xmldb:exist://127.0.0.1:8080/xmlrpc/db/apps/exist-docs
<project xmlns:xdb="http://exist-db.org/ant" default="upload-exist-docs-app"
name="eXist Load Example">
<!-- this is where we set our exist-home, user, password and the place that we will load the docs -->
<property file="local.properties"/>
<!-- this tells us where to find the key jar files relative to the ${exist-home} property -->
<path id="classpath.core">
<fileset dir="${exist-home}/lib/core">
<include name="*.jar"/>
</fileset>
<pathelement path="${exist-home}/exist.jar"/>
<pathelement path="${exist-home}/exist-optional.jar"/>
</path>
<typedef resource="org/exist/ant/antlib.xml" uri="http://exist-db.org/ant">
<classpath refid="classpath.core"/>
</typedef>
<!-- upload app -->
<target name="upload-exist-docs-app">
<echo message="Loading eXist documentation system to eXist."/>
<xdb:store uri="${uri}" createcollection="true"
createsubcollections="true" user="admin" password="">
<fileset dir="${exist-docs}">
<include name="**/*.*"/>
</fileset>
</xdb:store>
</target>
<target name="show-properties">
<echo message="exist-home=${exist-home}"/>
<echo message="exist-docs=${exist-docs}"/>
<echo message="uri=${uri}"/>
</target>
</project>
eXist store 任务的文档在这里:http://exist-db.org/exist/apps/doc/ant-tasks.xml#D2.2.10