<?xml version="1.0" encoding="UTF-8" ?> <project name="javaTest" default="sshexec8081" basedir="."> <property name="server" value="192.168.0.112"/> <property name="user" value="root"/> <property name="password" value="root"/> <property name="command" value="java -jar /home/shutong/helloworld.jar"/> <target name="clean"> <delete dir="build"/> </target> <target name="compile" depends="clean"> <mkdir dir="build/classes"/> <javac srcdir="src" destdir="build/classes"/> </target> <target name="run" depends="compile"> <java classname="HelloWorld"> <classpath><pathelement path="build/classes"/></classpath> </java> </target> <target name="jar" depends="run"> <jar destfile="helloworld.jar" basedir="build/classes"> <manifest> <attribute name="Main-class" value="HelloWorld"/> </manifest> </jar> </target> <property name="name" value="amigo"/> <property name="age" value="25"/> <target name="sshexecdelete" description="delete"> <sshexec host="${server}" username="${user}" password="${password}" port="22" trust="true" command="rm -rf /home/shutong/helloworld.jar" /> <echo message="删除目标jar包成功" /> </target> <target name="myscp" depends="jar,sshexecdelete"> <scp file="./helloworld.jar" todir="${user}:${password}@${server}:/home/shutong/" trust="true"/> <echo message="连接上传${server}服务器成功" /> </target> <target name="sshexec8081" depends="myscp" description="8081"> <sshexec host="${server}" username="${user}" password="${password}" port="22" trust="true" command="${command}" /> <echo message="程序执行成功" /> </target> </project>