Monday, May 4, 2009

Setting and echoing the classpath information using Ant

Setting classpath is a must (although not 'required' by default) to get anything useful done with Ant's javac/java tasks. One way of setting classpath is by using the 'path' element as follows:
 <path id="application.classpath">  
      <pathelement path="${java.class.path}"/>  
      <fileset dir=".">  
           <include name="lib/*.jar"/>  
      </fileset>  
 </path>  
Then comes situations where you want to see the list of jars files contained in this classpath. Following simple Ant target will echo the content of the classpath variable ('application.classpath'):
 <target name="printClassPath">  
      <property name="appClasspath" refid="application.classpath"/>  
      <echo message="classpath= ${appClasspath}"/>  
 </target>  

No comments: