| Ant | |
| Ant 的安裝 <?xml version="1.0" encoding="UTF-8"?> <project default="all" name="pluto-project" basedir="."> <target name="all" depends="api, container, portal"> </target> <target name="clean" depends="api-clean, container-clean, portal-clean"> </target> <target name="api"> <property name="final.name" value="portlet-api-@@DATE@@"/> <ant antfile="build.xml" dir="api" target="jar" inheritAll="false" /> </target> <target name="api-clean"> <ant antfile="build.xml" dir="api" target="clean" inheritAll="false" /> </target> <target name="container" depends="api"> <ant antfile="build.xml" dir="container" target="jar" inheritAll="false" /> </target> <target name="container-clean"> <ant antfile="build.xml" dir="container" target="clean" inheritAll="false" /> </target> <target name="portal" depends="container"> <ant antfile="build.xml" dir="portal" target="jar" inheritAll="false" /> </target> <target name="portal-clean"> <ant antfile="build.xml" dir="portal" target="clean" inheritAll="false" /> </target> </project>
編譯java文件的操作 <target name="init"> <mkdir dir="${dist.dir}" /> <mkdir dir="${dist.classes.dir}" /> <mkdir dir="${dist.webapps.dir}" /> </target> <property name="lib.dir" value="${basedir}/lib" /> ……. <path id="classpath"> <fileset dir="${lib.dir}"> <include name="*.jar"/> </fileset> </path> …… <classpath refid="classpath" /> 作為classpath 引用預先定義的jar包位置,refid 指明了一個(gè)引用變量。一般在real-world情況下會(huì )這樣使用。簡(jiǎn)單的使用是這樣的: <javac srcdir="${src}" destdir="${build}" classpath="xyz.jar" debug="on" />
這個(gè)就是把編譯好的文件打成jar包的ant 腳本,和上面javac一樣,可以放在任意位置。很明顯destfile 就是 你想要打成的包,basedir就是你的目標class文件,其它的復雜參數手冊上都有,可以對照參考。 <jar destfile="${dist}/lib/app.jar"> <fileset dir="${build}/classes" excludes="**/Test.class" /> <fileset dir="${src}/resources"/> </jar> 復制文件操作 <copy todir="${dist.webapps.dir}/WEB-INF/lib" overwrite="true" flatten="true"> <fileset dir="${lib.dir}"> <include name="*.jar" /> <exclude name="j2ee.jar" /> </fileset> </copy>
<fileset dir="${lib.dir}"> <include name="*.jar" /> <exclude name="j2ee.jar" /> </fileset>
<copy file="myfile.txt" todir="../some/other/dir"/>
<copy file="myfile.txt" todir="../some/other/dir"/>
<copy todir="../new/dir"> <fileset dir="src_dir"/> </copy>
<copy todir="../backup/dir"> <fileset dir="src_dir"/> <filterset> <filter token="TITLE" value="Foo Bar"/> </filterset> </copy>
<target name="clean"> <delete dir="${dest.dir}"/> <delete file="${dest2.dir}"/> </target> 以上操作也是很容易理解的。 執行ant 腳本 在有build.xml 的目錄提示符下使用 ant 就可以了。如果是其他的名字,那就使用ant -buildfile 文件名 ,就可以了。 |
聯(lián)系客服