How to Run a Java file from ANT Script

 <java classname="com.mugil.tutor.Sample">
   <classpath path="test/classes/"></classpath>
 </java>

Where Sample points to Sample.class which we got through compilation and test/classes/ contains the Sample.class file. Below is the whole code in build.xml file

<project name="ANT2" default="copyTarget">
  <target name="copyTarget">
  <mkdir dir="test/classes/"/>
  <javac srcdir="src/com/mugil/tutor/" destdir="test/classes/" includeantruntime="false"></javac>
    <java classname="com.mugil.tutor.Sample">
  	<classpath path="test/classes/"></classpath>
     </java>
   </target>
</project>

How to get Current time in ANT Script

 <project name="default" default="target1">
     <target name="target1">		
	<tstamp>
	   <format property="current.time" pattern="yyyyMMdd" />
	   <format property="archive.name" pattern="'MyArchive_'yyyyMMdd_hh:mmaa'.jar'" />
	</tstamp>
	<echo>${current.time}</echo>
	<echo>${archive.name}</echo>		
     </target>
</project>

ANT Script to concatenate two variables and Create directory based on that

<project name="default" default="target1">
  <property name="mugil.dir" value="D:/Mugilvannan/"/>		
     <target name="target1">		
	<tstamp>
	  <format property="current.time" pattern="yyyyMMdd" />
	  <format property="archive.name" pattern="'MyArchive_'yyyyMMdd_hhmmaa" />
	</tstamp>
	<property name="whole.dir" value="${mugil.dir}${archive.name}"/>
	  <echo>
	    ${whole.dir}
	  </echo>		
	<mkdir dir="${whole.dir}"></mkdir>
     </target>
</project>
Posted in ANT.

Leave a reply