Ant 中 如何 echo 机器名?
下面这个 build.xml 中。
<?xml version="1.0" ?>
<project name="BlackLineSelenium" default="junitReport" basedir=".">
<property name="source.dir" value="src" />
<property name="build.dir" value="build" />
<property name="lib.dir" value="lib" />
<property name="classes.dir" value="${build.dir}/classes" />
<property name="report.dir" value="report"/>
<property environment="env"/>
<property name="env.HOSTNAME" value="${env.COMPUTERNAME}"/>
<echo message="hostname = ${env.HOSTNAME}"/>
<exec executable="hostname" outputproperty="computer.hostname"/>
<!--<hostinfo prefix="eos" host="apache.org" ADDR4="140.211.11.130"/>-->
<target name="clean">
<delete dir="${classes.dir}" />
<mkdir dir="${classes.dir}" />
<delete dir="${report.dir}" />
<mkdir dir="${report.dir}" />
<echo> message="Base dir is: ${basedir}"</echo>
<echo> message="source.dir is: ${source.dir}"</echo>
<echo> message="build.dir is: ${build.dir}"</echo>
<echo> message="lib.dir is: ${lib.dir}"</echo>
<echo> message="classes.dir is: ${classes.dir}"</echo>
<echo> message="report.dir is: ${report.dir}"</echo>
</target>
<target name="compile" depends="clean">
<patternset id="lib.includes.compile">
<include name="*.jar" />
</patternset>
<fileset dir="${lib.dir}" id="lib.compile">
<patternset refid="lib.includes.compile" />
</fileset>
<pathconvert targetos="windows" property="libs.compile" refid="lib.compile" />
<!-- compile -->
<javac srcdir="${source.dir}" destdir="${classes.dir}" classpath="${libs.compile}" includes="**/*.java" debug="true" />
<copy todir="${classes.dir}">
<fileset dir="${source.dir}">
<include name="**/*.properties" />
<include name="**/*.xml" />
</fileset>
</copy>
</target>
<target name="junit" depends="compile">
<junit printsummary="yes" fork="true" haltonfailure="false" failureproperty="tests.failed" showoutput="true">
<classpath>
<pathelement path="${classes.dir}" />
<fileset dir="${lib.dir}">
<include name="*.jar" />
</fileset>
</classpath>
<formatter type="xml" />
<batchtest todir="${report.dir}">
<fileset dir="${classes.dir}">
<include name="**/TestAll.class" />
</fileset>
</batchtest>
</junit>
</target>
<target name="executeRemote">
<sshexec host="10.1.3.50"
username="sshuser"
password="qqqqq"
trust="true"
command="D:\bat.bat"/>
</target>
<target name="simpletask">
<taskdef name="simpletask" classname="com.xbosoft.blackline.AntSimpleTask" classpath="${build.dir}/classes"/>
<simpletask/>
</target>
<target name="junitReport" depends="junit">
<!--
<junitreport todir="report">
<fileset dir="report">
<include name="TEST-*.xml" />
</fileset>
-->
<!-- Allen added-->
<!--
<report styledir="reportstyle" format="frames" todir="report" />
</junitreport>
<fail if="tests.failed" />
-->
</target>
</project>
或者使用 <SSHEXEC> 执行一个外部命令
<target name="executeRemote">
<sshexec host="10.1.3.50"
username="sshuser"
password="qqqqq"
trust="true"
command="hostname"/>
</target>