[an error occurred while processing this directive]

Convert the path in to properties

                         

This example illustrates how to convert path in to properties. In this example, refid is a reference to an object defined elsewhere in the file. The reference allows you to reuse the chunks of the build file so that common classpath and path can be shared among targets. Many tasks have a refid attribute assigning the value of reference object to the property name with the name attribute. In this example, the java file is converted from src directory to build directory and the lib directory refers to the common lib directory of apache tomcat home directory. The path of tomcat home is changed in to the property name. The source code of build.xml is as follows:

 

 

 

<?xml version="1.0" encoding="UTF-8"?>
<project name="convert path" 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"/>

  <path id="project.classpath">
    <pathelement location="${dir.src}"/>
    <fileset dir="${tomcatHome}/common/lib">
      <include name="*.jar"/>
    </fileset>    
    <fileset dir="${dir.lib}">
      <include name="*.jar"/>
    </fileset>
  </path>

  <target name="clean">
    <delete dir="${dir.build}"/>
    <delete dir="${dir.lib}"/>
  </target>

  <target name="prepare" depends="clean">
    <mkdir dir="${dir.build}"/>
    <mkdir dir="${dir.lib}"/>
    <mkdir dir="${dir.src}"/>
  </target>

  
<target name="compile" depends="prepare">
    <pathconvert targetos="windows" property="windowsPath" refid="project.classpath"/>
    <echo>Path Directory = ${windowsPath}</echo>
    <javac destdir="${dir.build}" srcdir="${dir.src}">
      <classpath refid="project.classpath"/>
    </javac>
  </target>

</project>

 

If you run the program, the following output will be generated.


Download Source Code
 

                         

[an error occurred while processing this directive]