1 <?xml version="1.0" encoding="UTF-8"?> 2 3 <project name="项目名称" basedir="." default="sshexec"> 4 <description>本配置文件供ANT编译项目、自动进行单元测试、打包并部署之用。</description> 5 <description>默认操作(输入命令:ant)为编译源程序并发布运行。</description> 6 7 <!--属性设置--> 8 <property environment="env" /> 9 <property file="build.properties" /> 10 <property name="src.dir" value="${basedir}/src" /> 11 <property name="java.lib.dir" value="${env.JAVA_HOME}/lib" /> 12 <property name="classes.dir" value="${basedir}/classes" /> 13 <property name="dist.dir" value="${basedir}/dist" /> 14 <property name="project.lib.dir" value="${basedir}/lib" /> 15 <property name="localpath.dir" value="${basedir}" /> 16 <property name="remote.host" value="hadoopsys"/> 17 <property name="remote.username" value="hadoop"/> 18 <property name="remote.password" value="hadoop"/> 19 <property name="remote.home" value="~"/> 20 <!--每次需要知道的main类,写到这里--> 21 <property name="main.class" value="rpc.MyClient"/> 22 23 <!-- 基本编译路径设置 --> 24 <path id="compile.classpath"> 25 <fileset dir="${java.lib.dir}"> 26 <include name="tools.jar" /> 27 </fileset> 28 <fileset dir="${project.lib.dir}"> 29 <include name="*.jar" /> 30 </fileset> 31 </path> 32 33 <!-- 运行路径设置 --> 34 <path id="run.classpath"> 35 <path refid="compile.classpath" /> 36 <pathelement location="${classes.dir}" /> 37 </path> 38 <!-- 清理,删除临时目录 --> 39 <target name="clean" description="清理,删除临时目录"> 40 <!--delete dir="${build.dir}" /--> 41 <delete dir="${dist.dir}" /> 42 <delete dir="${classes.dir}" /> 43 <echo level="info">清理完毕</echo> 44 </target> 45 <!-- 初始化,建立目录,复制文件 --> 46 <target name="init" depends="clean" description="初始化,建立目录,复制文件"> 47 <mkdir dir="${classes.dir}" /> 48 <mkdir dir="${dist.dir}" /> 49 </target> 50 <!-- 编译源文件--> 51 <target name="compile" depends="init" description="编译源文件"> 52 <javac srcdir="${src.dir}" destdir="${classes.dir}" source="1.7" target="1.7" includeAntRuntime="false"> 53 <classpath refid="compile.classpath" /> 54 </javac> 55 </target> 56 57 <!-- 打包类文件 --> 58 <target name="jar" depends="compile" description="打包类文件"> 59 <jar jarfile="${dist.dir}/jar.jar"> 60 <fileset dir="${classes.dir}" includes="**/*.*" /> 61 </jar> 62 </target> 63 64 <!--上传到服务器 65 **需要把lib目录下的jsch-0.1.51拷贝到$ANT_HOME/lib下,如果是Eclipse下的Ant环境必须在Window->Preferences->Ant->Runtime->Classpath中加入jsch-0.1.51。 66 --> 67 <target name="ssh" depends="jar"> 68 <scp file="${dist.dir}/jar.jar" todir="${remote.username}@${remote.host}:${remote.home}" password="${remote.password}" trust="true"/> 69 </target> 70 71 <target name="sshexec" depends="ssh"> 72 <sshexec host="${remote.host}" username="${remote.username}" password="${remote.password}" trust="true" command="source /etc/profile; hadoop jar ${remote.home}/jar.jar ${main.class}"/> 73 </target> 74 </project>
时间: 2024-09-29 15:30:52