My question is How can I catch the arguments in the terminal using ant to run the main with these parameters, example:
ant 1 2 3 4 5
public static void main(String[] args)
{
int[] meta = {0,0,0,0,0};
for(int i=1; i < 6; i++)
{
meta[i-1] = Integer.parseInt(args[i]);
}
}
How can i do this, somebody help me pls C:? Here my build.xml
<project name="Tarea2LP" basedir="." default="main">
<property name="src.dir" value="src"/>
<property name="classes.dir" value="classes"/>
<property name="jar.dir" value="jar"/>
<property name="main-class" value="Board"/>
<target name="clean">
<delete dir="${classes.dir}"/>
<delete dir="${jar.dir}"/>
</target>
<target name="compile">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}"/>
</target>
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
</jar>
</target>
<target name="run" depends="jar">
<java jar="${jar.dir}/${ant.project.name}.jar" fork="true"/>
</target>
<target name="main" depends="run"/>
</project>
If the number of arguments is known you can use the -D option to pass in the argument and then in your "run" task target use 'arg' to pass it to jar file like
<target name="run" depends="jar">
<java jar="${jar.dir}/${ant.project.name}.jar" fork="true">
<arg value="${arg1}"/>
<arg value="${arg2}"/>
<arg value="${arg3}"/>
<arg value="${arg4}"/>
<arg value="${arg5}"/>
</java>
</target>
and you should invoke your ant file as
ant -Darg1=1 -Darg2=2 -Darg3=3 -Darg4=4 -Darg5=5