Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Tutorials Ant Convert the path in to properties

Related Tutorials


 
 

Share on Google+Share on Google+

Convert the path in to properties

Advertisement
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.

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
 

     

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: September 6, 2008

Related Tutorials

Discuss: Convert the path in to properties  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com