java: ant 脚本示例

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 
 3 <!--basedir是从build.xml所在的目录为基础算起的-->
 4 <project name="acm-rest-service" default="copy" basedir="../../../">
 5 
 6     <!--定义常用目录属性-->    
 7     <property name="encoding" value="UTF-8" />
 8     <property name="deploy.name" value="acm-rest-service" />    
 9     <property name="src.dir" value="${basedir}/SourceCode/JavaSource/mulms/cn/com/infosky/mulms/service/rest" />
10     <property name="lib.dir" value="${basedir}/SourceCode/JavaSource/lib" />
11     <property name="config.dir" value="${basedir}/Config/mulms/rest" />
12     <property name="target.dir" value="C:/deploy/mulms/${deploy.name}" />
13     <property name="output.web-inf.dir" value="${target.dir}/WEB-INF"/>
14     <property name="classes.dir" value="${output.web-inf.dir}/classes" />
15     <property name="output.lib.dir" value="${output.web-inf.dir}/lib" />
16 
17     <!--编译时的classpath-->
18     <path id="classpath">
19         <fileset dir="${lib.dir}">
20             <include name="**/*.jar" />
21         </fileset>
22     </path>
23 
24     <!--初始化,创建主要输出目录-->
25     <target name="init">
26         <mkdir dir="${target.dir}" />
27         <mkdir dir="${classes.dir}" />
28         <mkdir dir="${output.lib.dir}" />
29     </target>
30 
31     <!--清空输出内容-->
32     <target name="clean">
33         <delete includeEmptyDirs="true" dir="${target.dir}" />
34     </target>
35 
36     <!-- 编译 -->
37     <target name="compile" depends="init">
38         <javac srcdir="${src.dir}" destdir="${classes.dir}" debug="true" encoding="${encoding}" includeantruntime="false">
39             <classpath refid="classpath" />
40         </javac>
41     </target>
42 
43     <!--复制相应的文件-->
44     <target name="copy" depends="clean,compile">    
45 
46         <!--将所有依赖的jar文件复制到web-inf/lib目录下-->
47         <copy todir="${output.lib.dir}" overwrite="yes" flatten="true">
48             <fileset dir="${lib.dir}/jsr-rs">
49                 <include name="**/*.jar" />
50             </fileset>
51         </copy>
52         
53         <!--将web.xml复制到web-inf下-->
54         <copy todir="${output.web-inf.dir}" overwrite="yes" flatten="true">
55             <fileset dir="${config.dir}">
56                 <include name="**/*.xml" />
57             </fileset>
58         </copy>
59     </target>
60     
61     <!--生成war包-->
62     <target name="webwar" depends="copy">
63         <war webxml="${output.web-inf.dir}/web.xml" destfile="${target.dir}/../${deploy.name}.war">
64             <fileset dir="${target.dir}/">
65                 <include name="**/*.*" />
66             </fileset>
67         </war>
68     </target>
69 </project>

 

你可能感兴趣的:(java)