alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Ant example source code file (loadproperties.xml)

This example Ant source code file (loadproperties.xml) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Ant tags/keywords

abesea, abesea, c, c, iso-8859-1, port, port, server, server

The loadproperties.xml source code

<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="loadproperties-test" 
         basedir="." 
         default="testPrefixedProperties">

  <target name="init">
  </target>

  <target name="testPrefixedProperties" depends="init">
    <property name="server" value="localhost"/>
    <echo file="properties.tmp">
#http.@PORT@ = 90
http.@PORT@ = 80
http.@SERVER@ = ${server}
    </echo>
    <loadproperties srcFile="properties.tmp">
      <filterchain>
        <striplinecomments>
          <comment value="#"/>
        </striplinecomments>
        <prefixlines prefix="server1."/>
        <replacetokens>
          <token key="PORT" value="port"/>
          <token key="SERVER" value="server"/>
        </replacetokens>
        <expandproperties/>
      </filterchain>
    </loadproperties>
    <property name="server1.http.url" 
      value="http://${server1.http.server}:${server1.http.port}"/>
  </target>

  <target name="write properties.tmp" depends="init">
    <echo file="properties.tmp">
#tpfr.a=a
tpfr.a=A
tpfr.b=b\
       e
tpfr.c=@C@
    </echo>
  </target>

  <target name="testPropertiesFromResource" depends="write properties.tmp">
    <loadproperties resource="properties.tmp" classpath="${basedir}">
      <filterchain>
        <replacetokens>
          <token key="C" value="sea"/>
        </replacetokens>
      </filterchain>
    </loadproperties>
  </target>

  <target name="testPropertiesFromFileSet" depends="write properties.tmp">
    <loadproperties>
      <fileset dir="${basedir}">
        <include name="properties.tmp"/>
      </fileset>
      <filterchain>
        <replacetokens>
          <token key="C" value="sea"/>
        </replacetokens>
      </filterchain>
    </loadproperties>
  </target>

  <target name="loadPropertiesCheck">
    <condition property="testPropertiesFromResource.ok">
        <equals arg1="Abesea" arg2="${tpfr.a}${tpfr.b}${tpfr.c}" />
    </condition>
    <fail unless="testPropertiesFromResource.ok">
$${tpfr.a}$${tpfr.b}$${tpfr.c}="${tpfr.a}${tpfr.b}${tpfr.c}"
    </fail>
  </target>

  <target name="cleanup">
    <delete file="properties.tmp"/>
  </target>

</project>

Other Ant examples (source code examples)

Here is a short list of links related to this Ant loadproperties.xml source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.