Server端测试脚本
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="run_server" name="ant_server">
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
<target name="run_server">
<antserver port="12338"/>
<echo message="ycg--- >>> server running ..."/>
</target>
<target name="task.remote">
<echo message="ycg--- >>> build.type = ${build.type}"/>
<echo message="ycg--- >>> build.time(in client) = ${build.time}"/>
</target>
<target name="task.remote2">
<property name="build.type" value="full" />
<echo message="ycg--- >>> build.type = ${build.type}"/>
</target>
</project>
Client端测试脚本
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="build_remote" name="ant_hello">
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
<tstamp>
<format property="vl.cur_datetime" pattern="yyyy-MM-dd HH:mm"/>
<format property="vl.cur_datetime_forfile" pattern="yyyy-MM-dd(HHmm)"/>
</tstamp>
<!-- test remote 1 -->
<target name="build_remote">
<remoteant machine="localhost" port="12338">
<runtarget target="task.remote">
<property name="build.type" value="full" />
<property name="build.time" value="${vl.cur_datetime}" />
</runtarget>
</remoteant>
</target>
<!-- test remote 2 -->
<target name="build_remote2">
<remoteant machine="localhost" port="12338">
<runtarget target="task.remote2">
<property name="build.type" value="full" />
</runtarget>
</remoteant>
</target>
<!-- 本地测试 -->
<target name="build">
<antcall target="task.local">
<param name="build.type" value="full" />
<param name="build.time" value="${vl.cur_datetime}" />
</antcall>
</target>
<target name="task.local">
<echo message="ycg--- >>> build.type = ${build.type}"/>
<echo message="ycg--- >>> build.time(in client) = ${build.time}"/>
</target>
</project>
出现异常:
Buildfile: D:\MyProject\ResearchTest\Ant\ant.remote\client\build.xml
build_remote:
BUILD FAILED
D:\MyProject\ResearchTest\Ant\ant.remote\client\build.xml:12: java.io.EOFExcepti
on
at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputSt
ream.java:2554)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1297)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
at net.sf.antcontrib.antserver.client.Client.sendCommand(Client.java:233
)
at net.sf.antcontrib.antserver.client.ClientTask.execute(ClientTask.java
:144)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:392)
at org.apache.tools.ant.Target.performTasks(Target.java:413)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe
cutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.Main.runBuild(Main.java:811)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Total time: 0 seconds
解决方法:
下载Xerces-J-bin.2.11.0.zip,将其中两个文件复制到 ant/lib 目录下即可
xercesImpl.jar
xml-apis.jar