*************************************Main.java***************************
package test;
import java.io.*;
public class Main {
public static void main(String[] args) {
String text = "The args are as follows./n" ;
for (int i = 0; i < args.length; i++) {
text += args[i] + "/n" ;
}
try{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("output.txt")));
bw.write(text);
bw.close();
}catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
************************build.xml***************************************
<?xml version="1.0" encoding="UTF-8"?>
<project name="project" default="javaWithArgs">
<property name="newDir" value="build/classes" />
<property name="srcDir" value="src/test" />
<target name="mkdirForClasses">
<mkdir dir="${newDir}" />
</target>
<target name="compile" depends="mkdirForClasses">
<javac srcdir="${srcDir}" destdir="${newDir}" />
</target>
<target name="javaWithArgs" depends="compile">
<java classname="test.Main" classpath="${newDir}">
<arg value="arg1"/>
<arg value="arg2" />
<arg file="." />
</java>
</target>
</project>
*************************output.txt*******************************************
The args are as follows.
arg1
arg2
E:/Ant