Java/Ant/Path Dir

Материал из Java эксперт
Версия от 06:37, 1 июня 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Ant path

 
<?xml version="1.0"?>
<project name="sample" default="test" basedir=".">
    <!--  NOTE: THE FOLLOWING LINES SHOULD BE EDITED FOR YOUR PROJECT:  -->
    <property name="root.project.name" value="demo2"/>
    <property name="test.class" value="test.TestSample"/>
   <!-- NOTE: THE REST OF THIS FILE CAN PROBABLY REMAIN UNCHANGED FOR YOUR NEW PROJECTS -->
   <property name="jar.module" value="${root.project.name}.jar"/>
    <path id="test.classpath">
        <pathelement location="dist/${jar.module}"/>
        <pathelement location="dist/test.jar"/>
    </path>
   <target name="compile">
      <mkdir dir="build"/>
      <javac destdir="build"
             debug="on"
             optimize="on">
         <src path="src"/>
      </javac>
   </target>
   <target name="makejar" depends="compile">
      <mkdir dir="dist"/>
      <jar jarfile="dist/${jar.module}">
         <fileset dir="build">
             <include name="**/*.class"/>
       <exclude name="test/*.class"/>
         </fileset>
       </jar>
      <jar jarfile="dist/test.jar">
         <fileset dir="build">
             <include name="test/*.class"/>
         </fileset>
       </jar>
      <delete dir="build"/>
   </target>
   <target name="test" depends="makejar">
      <java fork="no" failonerror="yes"
            classname="${test.class}">
          <classpath refid="test.classpath"/> 
          <arg line=""/>
      </java>
   </target>
   <target name="clean">
      <delete dir="build"/>
      <delete dir="dist"/>
   </target>
</project>





Ant task: make dir

 
<?xml version="1.0"?>
<project name="sample" default="test" basedir=".">
    <!--  NOTE: THE FOLLOWING LINES SHOULD BE EDITED FOR YOUR PROJECT:  -->
    <property name="root.project.name" value="demo2"/>
    <property name="test.class" value="test.TestSample"/>
   <!-- NOTE: THE REST OF THIS FILE CAN PROBABLY REMAIN UNCHANGED FOR YOUR NEW PROJECTS -->
   <property name="jar.module" value="${root.project.name}.jar"/>
    <path id="test.classpath">
        <pathelement location="dist/${jar.module}"/>
        <pathelement location="dist/test.jar"/>
    </path>
   <target name="compile">
      <mkdir dir="build"/>
      <javac destdir="build"
             debug="on"
             optimize="on">
         <src path="src"/>
      </javac>
   </target>
   <target name="makejar" depends="compile">
      <mkdir dir="dist"/>
      <jar jarfile="dist/${jar.module}">
         <fileset dir="build">
             <include name="**/*.class"/>
       <exclude name="test/*.class"/>
         </fileset>
       </jar>
      <jar jarfile="dist/test.jar">
         <fileset dir="build">
             <include name="test/*.class"/>
         </fileset>
       </jar>
      <delete dir="build"/>
   </target>
   <target name="test" depends="makejar">
      <java fork="no" failonerror="yes"
            classname="${test.class}">
          <classpath refid="test.classpath"/> 
          <arg line=""/>
      </java>
   </target>
   <target name="clean">
      <delete dir="build"/>
      <delete dir="dist"/>
   </target>
</project>





Build path unix

 
<?xml version="1.0"?>
<project name="Apache Ant Properties Project" default="build.path.unix" basedir=".">

  <target name="build.path.unix">
    <echo message="File: ${basedir}/build.xml"/>
    <echo message="Path: ${basedir}/build.xml;${basedir}/build.properties"/>
  </target> 

</project>





Convert path format from one os to another

 
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.    
#
# This file is used by build.xml 
#
# Global defaults
name=          Anakia
project=       anakia
version=       1.0
final.name=    ${project}-${version}
root.package=  org.apache.anakia
# compile switches
debug= on
optimize= on
deprecation= off
ant.build.dir= build
build.dir= ${app.dir}/bin
# The source tree runs through a filter copy task to
# allow substitution of version, date etc. and will
# end up in build.src
build.lib=       ${build.dir}/lib
build.test.lib=  ${build.dir}/test-lib
build.dest=      ${build.dir}/classes
build.test.dest= ${build.dir}/test-classes
build.javadoc=   ${build.dir}/apidocs
build.test=      ${build.dir}/test
build.docs=      ${build.dir}/docs
# Various local pathes in the distribution
src.java.dir=  ${app.dir}/src/java
test.java.dir= ${app.dir}/src/test
test.dir=      ${app.dir}/test
example.dir=   ${app.dir}/examples
xdocs.dir=     ${app.dir}/xdocs
# Running the tests
test.haltonerror= true
test.haltonfailure= true
# Building the distribution
dist.root= ${build.dir}/dist
dist.dir= ${dist.root}/${final.name}
# Set to Sun Javadocs
javadocs.ref.jsdk= http://java.sun.ru/j2se/1.4.2/docs/api/
# for the javadoc
javadoc.packagenames = ${root.package}.*
# attributes for the jar manifest
mf.package = ${root.package}
mf.extension.name = ${project}
mf.specification.title = Anakia is a XML-based text processor
mf.specification.vendor = Apache Software Foundation
mf.implementation.title = ${mf.package}
mf.implementation.vendor.id = org.apache
mf.implementation.vendor = Apache Software Foundation
mf.implementation.version = ${version}

# #######################################################################
#
# Downloading jars from ibiblio repository
#
# #######################################################################
# The default behaviour is to download dependency jars only when
# they are not already present.
# Set skip.jar.loading to true to never download any dependency jar,
# or force.jar.loading to true to always download all dependency jars.
skip.jar.loading= false
force.jar.loading= false
#
# Settings for the proxy to use for download. Change this if you must
# use a proxy from your host. If the proxy.host property is unset, no
# proxy is used.
proxy.host=
proxy.port= 80
#
# We download directly from the ibiblio maven repository
repo.url= http://www.ibiblio.org/maven
#
# Jars to be downloaded
jar.antlr.version= 2.7.5
jar.rumons-collections.version= 3.1
jar.rumons-lang.version= 2.1
jar.jdom.version= 1.0
jar.werken-xpath.version= 0.9.4
jar.junit.version= 3.8.1
jar.velocity.version= 1.5

<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements.  See the NOTICE file
 distributed with this work for additional information
 regarding copyright ownership.  The ASF licenses this file
 to you under the Apache License, Version 2.0 (the
 "License"); you may not use this file except in compliance
 with the License.  You may obtain a copy of the License at
   http://www.apache.org/licenses/LICENSE-2.0
 Unless required by applicable law or agreed to in writing,
 software distributed under the License is distributed on an
 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.    
-->
<!-- Build file for project -->
<!-- This project has its basedir set to the root directory   -->
<!-- of the project distribution. This is necessary so that   -->
<!-- all the code that uses relative directory references     -->
<!-- (like the tests) can be run in the same way when using   -->
<!-- the ant based build and the maven based build.           -->
<!-- *** DO NOT CHANGE THIS SETTING LIGHTLY! ***              -->
<project name="Anakia" default="world" basedir="..">
  <path id="basedir-os">
    <pathelement location="${basedir}" />
  </path>
  <!-- This is the relative base dir. This must be the root of the   -->
  <!-- distribution. All relative pathes are prefixed with      -->
  <!-- app.dir                                                  -->
  <pathconvert property="app.dir" refid="basedir-os" targetos="unix"/>
  <!-- Give user a chance to override without editing this file
       (and without typing -D each time it compiles it -->
  <property file="${user.home}/.ant.properties" />
  <property file="${user.home}/build.properties" />
  <property file=".ant.properties" />
  <!-- This file contains all the defaults for the build  -->
  <property file="build/build.properties" />

  <property name="test.runner" value="junit.textui.TestRunner"/>
  <target name="world" depends="jar,test,javadocs,docs,env"
          description="Build the project jar and documentation"/>
  
  <!-- prints the environment                                              -->
  
  <target name="env" description="Prints build parameters">
    <echo>
  Global settings:
    java.home = ${java.home}
    user.home = ${user.home}
    java.class.path = ${java.class.path}
  Project settings:
    Version:     ${version}
    Debug:       ${debug}
    Optimize:    ${optimize}
    Deprecation: ${deprecation}
  Target settings (relative to build tree root):
    Classes:      ${build.dest}
    API Docs:     ${build.javadoc}
    Docs:         ${build.docs}
    </echo>
  </target>
  
  <!-- Prepares the build directory                                        -->
  
  <target name="prepare" depends="basic-prepare"/>
  
  <!-- sets up the build trees for sources and tests                       -->
  
  <target name="basic-prepare">
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${build.dest}"/>
    <mkdir dir="${build.test.dest}"/>
  </target>
  
  <!-- sets up the build environment (classpath and libs)                  -->
  
  <target name="build-prepare" depends="basic-prepare">
    <ant antfile="${ant.build.dir}/download.xml" target="build-download" />
    <!-- Build classpath -->
    <path id="build.classpath">
      <fileset dir="${build.lib}">
        <include name="**/*.jar"/>
      </fileset>
    </path>
    <!-- Test classpath, contains dependencies needed only for Testing -->
    <path id="test.classpath">
        <fileset dir="${build.test.lib}">
          <include name="**/*.jar"/>
        </fileset>
        <fileset dir="${build.lib}">
          <include name="**/*.jar"/>
        </fileset>
        <pathelement location="${build.dest}" />
        <pathelement location="${build.test.dest}" />
    </path>
    <path id="run.classpath">
      <path refid="build.classpath"/>
      <pathelement location="${build.dir}/${final.name}.jar"/>
    </path>
  </target>
  
  <!-- Compiles the source tree and the tests                              -->
  
  <target name="compile" depends="compile-src,compile-test"/>
  <target name="compile-src" depends="build-prepare"
          description="Compiles the source">
    <javac srcdir="${src.java.dir}"
      destdir="${build.dest}"
      encoding="UTF-8"
      debug="${debug}"
      deprecation="${deprecation}"
      optimize="${optimize}"
      classpathref="build.classpath"/>
    <copy todir="${build.dest}" filtering="yes">
      <fileset dir="${src.java.dir}">
        <include name="**/*.properties"/>
      </fileset>
    </copy>
  </target>
  <target name="compile-test" depends="build-prepare,compile-src"
          description="Compiles the test classes">
    <javac srcdir="${test.java.dir}"
      destdir="${build.test.dest}"
      encoding="UTF-8"
      debug="${debug}"
      deprecation="${deprecation}"
      optimize="${optimize}">
      <!-- Don"t use the run classpath, build using the exploded class tree -->
      <classpath>
        <path refid="build.classpath"/>
        <path refid="test.classpath" />
        <pathelement location="${build.dest}"/>
      </classpath>
    </javac>
    <copy todir="${build.test.dest}" filtering="yes">
      <fileset dir="${test.java.dir}">
        <include name="**/*.properties"/>
      </fileset>
    </copy>
  </target>

  
  <!-- Compiles the source directory and creates a .jar file               -->
  
  <target name="jar" depends="compile-src"
          description="Builds the Jar file">
    <property name="jarname" value="${final.name}" />
    <jar jarfile="${build.dir}/${jarname}.jar">
      <metainf dir="${app.dir}">
        <include name="LICENSE"/>
        <include name="NOTICE"/>
      </metainf>
      <fileset dir="${build.dest}"/>
      <manifest>
        <attribute name="Created-By" value="Apache Ant"/>
        <attribute name="Build-Jdk" value="${java.version}"/>
        <attribute name="Package" value="${mf.package}"/>
        <attribute name="Extension-Name" value="${mf.extension.name}"/>
        <attribute name="Specification-Title" value="${mf.specification.title}" />
        <attribute name="Specification-Vendor" value="${mf.specification.vendor}"/>
        <attribute name="Implementation-Title" value="${mf.implementation.title}"/>
        <attribute name="Implementation-Vendor-Id" value="${mf.implementation.vendor.id}"/>
        <attribute name="Implementation-Vendor" value="${mf.implementation.vendor}"/>
        <attribute name="Implementation-Version" value="${mf.implementation.version}"/>
      </manifest>
    </jar>
    <checksum file="${build.dir}/${jarname}.jar" algorithm="md5" property="checksum.jar.md5"/>
    <checksum file="${build.dir}/${jarname}.jar" algorithm="sha1" property="checksum.jar.sha1"/>
    <echo message="${checksum.jar.md5} *${jarname}.jar" file="${build.dir}/${jarname}.jar.md5" />
    <echo message="${checksum.jar.sha1} *${jarname}.jar" file="${build.dir}/${jarname}.jar.sha1" />
  </target>
  
  <!-- jars the source                                                    -->
  
  <target name="jar-src"
          depends="prepare"
          description="Builds the Source Jar File">
    <jar jarfile="${build.dir}/${final.name}-src.jar">
      <metainf dir="${app.dir}">
        <include name="LICENSE"/>
        <include name="NOTICE"/>
      </metainf>
      <fileset dir="${src.java.dir}"/>
      <manifest>
        <attribute name="Created-By" value="Apache Ant"/>
        <attribute name="Specification-Title" value="${mf.specification.title}" />
        <attribute name="Specification-Vendor" value="${mf.specification.vendor}"/>
        <attribute name="Implementation-Title" value="${mf.implementation.title}"/>
        <attribute name="Implementation-Vendor-Id" value="${mf.implementation.vendor.id}"/>
        <attribute name="Implementation-Vendor" value="${mf.implementation.vendor}"/>
        <attribute name="Implementation-Version" value="${mf.implementation.version}"/>
      </manifest>
    </jar>
    <checksum file="${build.dir}/${final.name}-src.jar" algorithm="md5" property="checksum.jar-src.md5"/>
    <checksum file="${build.dir}/${final.name}-src.jar" algorithm="sha1" property="checksum.jar-src.sha1"/>
    <echo message="${checksum.jar-src.md5} *${final.name}-src.jar" file="${build.dir}/${final.name}-src.jar.md5" />
    <echo message="${checksum.jar-src.sha1} *${final.name}-src.jar" file="${build.dir}/${final.name}-src.jar.sha1" />
  </target>
  
  <!-- Creates the API documentation                                       -->
  
  <target name="javadocs" depends="build-prepare"
          description="Creates the Javadoc API documentation">
    <mkdir dir="${build.javadoc}"/>
    <javadoc sourcepath="${src.java.dir}"
             packagenames="${javadoc.packagenames}"
             destdir="${build.javadoc}"
             author="true"
             private="false"
             version="true"
             use="true"
             windowtitle="${name} ${version} API"
             doctitle="${name} ${version} API"
             encoding="UTF-8"
             docencoding="UTF-8"
             bottom="Copyright &#169; 2000-${build.year} &lt;a href=&quot;http://www.apache.org/&quot;&gt;Apache Software Foundation&lt;/a&gt;. All Rights Reserved."
             classpathref="build.classpath">
      <link href="${javadocs.ref.jsdk}"/>
      <link href="http://www.jdom.org/docs/apidocs"/>
      <link href="http://logging.apache.org/log4j/docs/api"/>
      <link href="http://excalibur.apache.org/apidocs"/>
      <link href="http://tomcat.apache.org/tomcat-4.1-doc/servletapi"/>
      <link href="http://jakarta.apache.org/oro/api"/>
      <link href="http://jakarta.apache.org/commons/lang/api-release"/>
      <link href="http://jakarta.apache.org/commons/collections/api-release"/>
    </javadoc>
  </target>
  <target name="javadocs-clean">
    <delete dir="${build.javadoc}" quiet="true"/>
  </target>
  
  <!-- Package                                                             -->
  
  <target name="build-package-tree" depends="clean,jar,docs,javadocs">

    <mkdir dir="${dist.dir}"/>
    <mkdir dir="${dist.dir}/src/java"/>
    <copy todir="${dist.dir}/src/java/">
      <fileset dir="${src.java.dir}" />
    </copy>
    <copy todir="${dist.dir}/src/test/">
      <fileset dir="${test.java.dir}" />
    </copy>
    <copy todir="${dist.dir}/lib">
      <fileset dir="${build.lib}" />
    </copy>
    <copy todir="${dist.dir}/lib/test">
      <fileset dir="${build.test.lib}" />
    </copy>
    <copy todir="${dist.dir}/build">
      <fileset dir="${app.dir}/build">
        <include name="**"/>
        <exclude name="velocity.log"/>
      </fileset>
    </copy>
    <!-- Copy docs, exclude API docs -->
    <copy todir="${dist.dir}/docs">
      <fileset dir="${build.docs}">
        <include name="**"/>
        <exclude name="docs/api/**"/>
      </fileset>
    </copy>
    <!-- Add freshly built Java docs -->
    <copy todir="${dist.dir}/docs/api">
      <fileset dir="${build.javadoc}">
        <include name="**"/>
      </fileset>
    </copy>
    <copy todir="${dist.dir}/test">
      <fileset dir="${app.dir}/test">
        <include name="**"/>
      </fileset>
    </copy>
    <copy todir="${dist.dir}/xdocs">
      <fileset dir="${xdocs.dir}">
        <include name="**"/>
      </fileset>
    </copy>
    <copy todir="${dist.dir}">
      <fileset dir="${app.dir}">
        <include name="LICENSE" />
        <include name="NOTICE" />
        <include name="README.txt" />
        <include name="pom.xml" />
      </fileset>
    </copy>
    <copy
      file="${build.dir}/${final.name}.jar"
      tofile="${dist.dir}/${final.name}.jar"
    />
  </target>
  
  <!-- Packages the distribution with ZIP                                 -->
  
  <target name="package-zip"
          depends="build-package-tree">
    <!-- .zip built for Windows -->
    <fixcrlf srcdir="${dist.dir}" eol="crlf" eof="asis" encoding="ISO-8859-1">
      <include name="**/*.html" />
      <include name="**/*.java" />
      <include name="**/*.properties" />
      <include name="**/*.txt" />
      <include name="**/*.xml" />
    </fixcrlf>
    <delete file="${build.dir}/${final.name}.zip" quiet="true"/>
    <zip zipfile="${build.dir}/${final.name}.zip" basedir="${dist.root}"
         includes="**/${final.name}/**"/>
    <checksum file="${build.dir}/${final.name}.zip" algorithm="md5" property="checksum.zip.md5"/>
    <checksum file="${build.dir}/${final.name}.zip" algorithm="sha1" property="checksum.zip.sha1"/>
    <echo message="${checksum.zip.md5} *${final.name}.zip" file="${build.dir}/${final.name}.zip.md5" />
    <echo message="${checksum.zip.sha1} *${final.name}.zip" file="${build.dir}/${final.name}.zip.sha1" />
  </target>
  
  <!-- Packages the distribution with TAR-GZIP                            -->
  
  <target name="package-tgz"
          depends="build-package-tree">
    <!-- .tar.gz built for Unix -->
    <fixcrlf srcdir="${dist.dir}" eol="lf" eof="remove" encoding="ISO-8859-1">
      <include name="**/*.html" />
      <include name="**/*.java" />
      <include name="**/*.properties" />
      <include name="**/*.txt" />
      <include name="**/*.xml" />
    </fixcrlf>
    <delete file="${build.dir}/${final.name}.tar.gz" quiet="true"/>
    <tar tarfile="${build.dir}/${final.name}.tar.gz" basedir="${dist.root}"
         includes="**/${final.name}/**" longfile="gnu" compression="gzip" />
    <checksum file="${build.dir}/${final.name}.tar.gz" algorithm="md5" property="checksum.tgz.md5"/>
    <checksum file="${build.dir}/${final.name}.tar.gz" algorithm="sha1" property="checksum.tgz.sha1"/>
    <echo message="${checksum.tgz.md5} *${final.name}.tar.gz" file="${build.dir}/${final.name}.tar.gz.md5" />
    <echo message="${checksum.tgz.sha1} *${final.name}.tar.gz" file="${build.dir}/${final.name}.tar.gz.sha1" />
  </target>

  
  <!-- Packages the distribution with ZIP and TAR-GZIP                    -->
  
  <target name="package"
          depends="package-zip,package-tgz"
          description="Generates the distribution files">
  </target>
  
  
  <!-- Cleans up the build directory. Leave Libs unharmed to avoid re-download -->
  
  <target name="clean" 
          description="Cleans all generated files except downloaded libs">
    <delete includeEmptyDirs="true" quiet="true">
      <fileset dir="${build.dir}" defaultexcludes="no">
        <exclude name="lib/**" />
        <exclude name="test-lib/**" />
      </fileset>
      <fileset dir="${ant.build.dir}" defaultexcludes="no">
        <include name="velocity.log" />
      </fileset>
    </delete>
  </target>
  
  <!-- Really cleans up the build directory                                -->
  
  <target name="real-clean" 
          description="Cleans all generated files">
    <delete includeEmptyDirs="true" quiet="true" dir="${build.dir}" />
  </target>
  
  <!-- Make HTML version of the documentation                         -->
  
  <target name="docs" depends="build-prepare,jar"
          description="Generates the HTML documentation">
    <taskdef name="anakia"
             classname="org.apache.anakia.AnakiaTask"
             classpathref="run.classpath"/>
    <echo>
  #######################################################
  #
  #  Now using Anakia to transform the XML documentation
  #  to HTML.
  #######################################################
    </echo>
    <anakia basedir="${xdocs.dir}/docs" destdir="${build.docs}"
         extension=".html" style="site.vsl"
         projectFile="../stylesheets/project.xml"
         includes="**/*.xml"
         lastModifiedCheck="true"
         templatePath="${xdocs.dir}/stylesheets">
    </anakia>
    <copy todir="${build.docs}/images" filtering="no">
        <fileset dir="${xdocs.dir}/images">
            <include name="**/*.gif"/>
            <include name="**/*.jpeg"/>
            <include name="**/*.jpg"/>
            <include name="**/*.png"/>
        </fileset>
    </copy>
    <copy todir="${build.docs}" filtering="no">
        <fileset dir="${xdocs.dir}">
            <include name="**/*.css"/>
            <include name="**/.htaccess"/>
        </fileset>
    </copy>
  </target>

  
  <!-- Cleans up the docs directory                                       -->
  
  <target name="docs-clean">
    <delete dir="${build.docs}" quiet="true"/>
  </target>

  
  <!-- JUnit Tests                                                         -->
  
  <target name="test-clean">
    <delete dir="${build.test.dest}" quiet="true"/>
    <delete dir="${build.test}" quiet="true"/>
    <delete dir="${build.test.reports}" quiet="true"/>
  </target>

  <target name="test"
          depends="build-prepare,compile-test,test-anakia"/>

  <target name="test-anakia">
    <echo message="Running Anakia tests..."/>
    <taskdef name="anakia" classname="org.apache.anakia.AnakiaTask"
             classpathref="test.classpath"/>
    <!-- run twice - once with custom context and once without -->
    <anakia basedir="${test.dir}/anakia/xdocs"
            destdir="${build.test}/anakia"
        extension=".html" style="./site_contexts.vsl"
        projectFile="./stylesheets/project.xml"
        excludes="**/stylesheets/**"
        includes="**/*.xml"
        templatePath="${test.dir}/anakia/xdocs/stylesheets"
        lastModifiedCheck="false">
    </anakia>
    <anakia basedir="${test.dir}/anakia/xdocs"
            destdir="${build.test}/anakia"
        extension=".context.html" style="./site_contexts.vsl"
        projectFile="./stylesheets/project.xml"
        excludes="**/stylesheets/**"
        includes="**/*.xml"
        templatePath="${test.dir}/anakia/xdocs/stylesheets"
        lastModifiedCheck="false">
        <context name="customContext" file="./stylesheets/customContext.xml"/>
    </anakia>
    <java classname="${test.runner}" fork="yes" dir="${app.dir}" failonerror="${test.haltonerror}"
          classpathref="test.classpath">
      <arg value="org.apache.anakia.AnakiaTestCase"/>
    </java>
  </target>

</project>





Define path with file set

 
<?xml version="1.0" encoding="UTF-8"?>
<project name="Classpath Sample" default="compile" basedir=".">
  <property environment="env"/>
  <property name="tomcatHome" value="${env.TOMCAT_HOME}"/>
  <property name="dir.src" value="src"/>
  <property name="dir.build" value="build"/>
  <property name="dir.lib" value="lib"/>
  
  <!-- Define a classpath for use throughout the buildfile -->
  <path id="project.classpath">
    <pathelement location="${dir.src}"/>
    <!-- include Tomcat libraries -->
    <fileset dir="${tomcatHome}/common/lib">
      <include name="*.jar"/>
    </fileset>    
    <!-- include our own libraries -->
    <fileset dir="${dir.lib}">
      <include name="*.jar"/>
    </fileset>
  </path>
  
  <target name="clean">
    <delete dir="${dir.build}"/>
  </target>
  
  <target name="prepare">
    <mkdir dir="${dir.build}"/>
    
    <!-- just create a dummy directory for this fake buildfile -->
    <mkdir dir="${dir.lib}"/>
  </target>
  
  <target name="compile" depends="prepare">
    <!-- use <pathconvert> to convert the path into a property -->
    <pathconvert targetos="windows" property="windowsPath" refid="project.classpath"/>
    <!-- now echo the path to the console -->
    <echo>Windows path = ${windowsPath}</echo>
        
    <!-- Here is how to use the classpath for compiling -->
    <javac destdir="${dir.build}">
      <src path="${dir.src}"/>
      <classpath refid="project.classpath"/>
    </javac>
  </target>
</project>





File separator

 
<?xml version="1.0"?>
<project name="Apache Ant Properties Project" default="build.path" basedir=".">
  <target name="build.path">
    <echo message="File: ${basedir}${file.separator}build.xml"/>
    <echo message="Path: ${basedir}${file.separator}build.xml${path.separator}${basedir}${file.separator}build.properties"/>
  </target>
</project>





Get current location

 
<?xml version="1.0"?>
<project name="Apache Ant Properties Project" default="properties.custom" basedir=".">
  <target name="properties.custom">
    <property name="project.dtd" location="project.dtd"/>
    <echo message="Location of project.dtd: ${project.dtd}"/>
  </target>
</project>





Path convert

 
<?xml version="1.0" encoding="UTF-8"?>
<project name="Classpath Sample" default="compile" basedir=".">
  <property environment="env"/>
  <property name="tomcatHome" value="${env.TOMCAT_HOME}"/>
  <property name="dir.src" value="src"/>
  <property name="dir.build" value="build"/>
  <property name="dir.lib" value="lib"/>
  
  <!-- Define a classpath for use throughout the buildfile -->
  <path id="project.classpath">
    <pathelement location="${dir.src}"/>
    <!-- include Tomcat libraries -->
    <fileset dir="${tomcatHome}/common/lib">
      <include name="*.jar"/>
    </fileset>    
    <!-- include our own libraries -->
    <fileset dir="${dir.lib}">
      <include name="*.jar"/>
    </fileset>
  </path>
  
  <target name="clean">
    <delete dir="${dir.build}"/>
  </target>
  
  <target name="prepare">
    <mkdir dir="${dir.build}"/>
    
    <!-- just create a dummy directory for this fake buildfile -->
    <mkdir dir="${dir.lib}"/>
  </target>
  
  <target name="compile" depends="prepare">
    <!-- use <pathconvert> to convert the path into a property -->
    <pathconvert targetos="windows" property="windowsPath" refid="project.classpath"/>
    <!-- now echo the path to the console -->
    <echo>Windows path = ${windowsPath}</echo>
        
    <!-- Here is how to use the classpath for compiling -->
    <javac destdir="${dir.build}">
      <src path="${dir.src}"/>
      <classpath refid="project.classpath"/>
    </javac>
  </target>
</project>





Path separator

 
<?xml version="1.0"?>
<project name="Apache Ant Properties Project" default="build.path" basedir=".">
  <target name="build.path">
    <echo message="File: ${basedir}${file.separator}build.xml"/>
    <echo message="Path: ${basedir}${file.separator}build.xml${path.separator}${basedir}${file.separator}build.properties"/>
  </target>
</project>





Path with pathelement

 
<?xml version="1.0"?>
<project name="yourName" default="junitgui" basedir=".">
  <property name="junitJar" value="\junit3.8.1\junit.jar" />
  <property name="src.dir" value="${basedir}\src" />
  <property name="build.dir" value="${basedir}\classes" />
  <path id="classpath">
    <pathelement location="${junitJar}" />
    <pathelement location="${build.dir}" />
  </path>
  <target name="init">
    <mkdir dir="${build.dir}" />
  </target>
  <target name="build" depends="init" description="build all">
    <javac
        srcdir="${src.dir}" destdir="${build.dir}"
        source="1.5" 
        deprecation="on" debug="on" optimize="off" includes="**">
      <classpath refid="classpath" />
    </javac>
  </target>
  <target name="junitgui" depends="build" description="run junitgui">
    <java classname="junit.awtui.TestRunner" fork="yes">
      <arg value="sis.AllTests" />
      <classpath refid="classpath" />
    </java>
  </target>
   <target name="clean">  
    <delete dir="${build.dir}" />
  </target>
   <target name="rebuildAll" depends="clean,build" description="rebuild all"/>
</project>





Specify basedir

 
<?xml version="1.0"?>
<project name="Apache Ant Properties Project" default="properties.built-in" basedir=".">
  <target name="properties.built-in">
    <echo message="The base directory: ${basedir}"/>      
    <echo message="This file: ${ant.file}"/>
    <echo message="Ant version: ${ant.version}"/> 
    <echo message="Project name: ${ant.project.name}"/>     
    <echo message="Java version: ${ant.java.version}"/>     
  </target>
</project>