Configurating datasources with ant?

Stefan Koch

A glance at the source code of the install task of tomcat tells me that it cannot replace tokens from a template configuration file.

You should use the ant <replace/> task, or <copy/> with a nested <filterchain> containing a nested <filterset/> element.

Example with filterset :

Will work with a template file where the tokens to be replaced are introduced and ended by backquotes.

Tokens are recognized by replacetokens with one beginning and one ending character. So tokens cannot look like an ant property ${some.property}

  <copy (appropriate attributes here)>
          <param type="tokenchar" name="begintoken" value="`"/>
          <param type="tokenchar" name="endtoken" value="`"/>
          <param type="token" name="dburl" value="${dburl}"/>
          <param type="token" name="driver" value="${driver}"/>
          <param type="token" name="username" value="${username}"/>
          <param type="token" name="password" value="${password}"/>

Additional info:
I can delete, update and deploy applications to Tomcat using the catalina-ant.jar tasks, but can I also create/edit datasource?

I would like my ant script to have the dburl, driver, username and password as propeties and automatically create the datasource and underlying connection pool (using those settings).

For the install task you can specify a config file which contains the context definitions like in the server.xml

 <target name="install" description="Install web application" depends="createwar">
    <install url="${url}" username="${username}" password="${password}"
            path="${path}" war="file://${basedir}/${warfile}"

<Context className="org.apache.catalina.core.StandardContext" 
         crossContext="false" reloadable="true"
         useNaming="true" debug="0" swallowOutput="false" 
         docBase="/opt/jakarta-tomcat-4.1.24/webapps/home" cookies="true"
         path="/home" cachingAllowed="true" privileged="false"
  <Logger className="org.apache.catalina.logger.FileLogger" debug="0"
          verbosity="1" prefix="homepage" directory="logs"
          timestamp="true" suffix=".log"/>
  <Resource name="jdbc/postgres" scope="Shareable" 
  <ResourceParams name="jdbc/postgres">

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.