build.xml
<project name="zdemo-hadoop-debug" basedir="." default="prepare">
<property name="myclasspath" value="/Users/zhangqingli/Documents/y/mylibs/hadoop/2.5.0/jar" />
<property name="targettarname" value="zdemo-hadoop-debug.jar" />
<target name="prepare">
<delete dir="${basedir}/build/classes" />
<mkdir dir="${basedir}/build/classes"/>
</target>
<path id="path1">
<fileset dir="${myclasspath}">
<include name="*.jar"/>
</fileset>
</path>
<target name="compile" depends="prepare">
<javac srcdir="${basedir}/src" destdir="${basedir}/build/classes" classpathref="path1" includeantruntime="true"/>
</target>
<target name="package" depends="compile">
<jar destfile="${basedir}/build/${targettarname}" basedir="${basedir}/build/classes" />
</target>
<target name="ssh" depends="package">
<scp todir="ubuntu@nimbusz:/opt/data" file="${basedir}/build/${targettarname}" password="xxx" />
<sshexec command="/opt/module/hadoop-2.5.0/bin/hdfs dfs -rm -r /user/ubuntu/test/output"
host="xxx" username="xxx" password="xxx" failonerror="false"/>
<sshexec command="/opt/module/hadoop-2.5.0/bin/yarn jar
/opt/data/zdemo-hadoop-debug.jar mr01.maxtemperature.MaxTemperatureApp
/user/ubuntu/test/maxtemperature /user/ubuntu/test/output"
host="xxx" username="xxx" password="xxx" />
</target>
</project>
注:使用ant的sshexec功能需要加入 jsch-xxx.jar