现在的位置: 首页 > 综合 > 正文

ant打包示例

2014年07月16日 ⁄ 综合 ⁄ 共 6568字 ⁄ 字号 评论关闭

<?xml version="1.0"?>
<project default="build_standardsm">
<import file="maven-build.xml" />
<property name="src.main.java.dir" value="src/main/java" />
<property name="src.main.resources.dir" value="src/main/resources" />
<property name="src.test.java.dir" value="src/test/java" />
<property name="src.test.resources.dir" value="src/test/resources" />
<!-- 交通银行的配置文件源路径 -->
<property name="src.test.resources_jtyh.dir" value="${src.test.resources.dir}/jtyh" />
<!-- 网关版的配置文件源路径 -->
<property name="src.test.resources_gateway.dir" value="${src.test.resources.dir}/gateway" />
<!-- 太平洋保险配置文件源路径 -->
<property name="src.test.resources_tpybx.dir" value="${src.test.resources.dir}/tpybx" />
<!-- 国泰君安配置文件源路径 -->
<property name="src.test.resources_gtja.dir" value="${src.test.resources.dir}/gtja" />
<!-- Jetty webapp源路径 -->
<property name="src.webapp" value="webapps" />
<!-- 一些配置文件源路径 -->
<property name="src.conf" value="conf" />
<!-- Jetty contexts源路径 -->
<property name="src.contexts" value="contexts" />
<!-- 目标根路径 -->
<property name="build.dir" value="./build" />
<!-- 编译目标路径 -->
<property name="build_compile.dir" value="${build.dir}/classes" />
<!-- Jetty webapp目标路径 -->
<property name="build.webapp" value="${build.dir}/webapps" />
<!-- 一些配置文件目标路径 -->
<property name="build.conf" value="${build.dir}/conf" />
<!-- Jetty contexts目标路径 -->
<property name="build.contexts" value="${build.dir}/contexts" />
<!-- 配置jetty log -->
<property name="build_jettylog.dir" value="${build.dir}/log" />
<!-- jar包目标路径 -->
<property name="build_lib.dir" value="${build.dir}/lib" />
<!-- 用于混淆的临时路径 -->
<property name="build_lib_obfuscate.dir" value="${build.dir}/lib_obfuscate" />

<!-- 初始化任务 -->
<target name="init" description="init">
   <!-- 删除 -->
   <delete dir="${build_compile.dir}" />
   <delete dir="${build.webapp}" />
   <delete dir="${build.conf}" />
   <delete dir="${build.contexts}" />
   <delete dir="${build_jettylog.dir}" />
   <delete dir="${build_lib.dir}" />
   <mkdir dir="${build_compile.dir}" />
   <mkdir dir="${build_lib.dir}" />
   <mkdir dir="${build_jettylog.dir}" />
</target>

<!-- 编译到build下的classes -->
<target name="compile" depends="init">
   <javac destdir="${build_compile.dir}" source="1.6" target="1.6" debug="true" deprecation="false" optimize="false" encoding="GBK" failonerror="true">
    <src path="${src.main.java.dir}:${src.main.resources.dir}" />
    <classpath refid="build.classpath" />
   </javac>
</target>

<!-- 编译到build下的classes_test -->
<target name="compile_test" depends="init">
   <javac destdir="${build_compile.dir}" source="1.6" target="1.6" debug="true" deprecation="false" optimize="false" encoding="GBK" failonerror="true">
    <src path="${src.main.java.dir}:${src.test.java.dir}" />
    <classpath refid="build.classpath" />
   </javac>
</target>

<!-- 将类打包成jar到目标路径 -->
<target name="classes_jar" depends="compile">
   <jar jarfile="${build_lib.dir}/${maven.build.finalName}.jar" compress="true" index="false" basedir="${build_compile.dir}" excludes="**/package.html" />
</target>

<!-- 将类打包成jar到目标路径 -->
<target name="classes_jar_test" depends="compile_test">
   <jar jarfile="${build_lib.dir}/${maven.build.finalName}-test.jar" compress="true" index="false" basedir="${build_compile.dir}" excludes="**/package.html" />
</target>

<!-- 拷贝类库到目标路径 -->
<target name="lib_copy" depends="init">
   <copy todir="${build_lib.dir}" flatten="true">
    <path refid="build.classpath" />
   </copy>
</target>

<!-- 拷贝配置文件到目标路径 -->
<target name="resources_copy" depends="init" description="copy the config files">
   <!-- 拷贝resources到目标路径 -->
   <copy todir="${build.conf}" includeEmptyDirs="no">
    <fileset dir="${src.test.resources.dir}">
     <patternset>
      <include name="*.properties" />
      <include name="*.xml" />
      <include name="*.dtd" />
     </patternset>
    </fileset>
   </copy>
   <!-- 拷贝webapp到目标路径 -->
   <copy todir="${build.webapp}">
    <fileset dir="${src.webapp}"/>
   </copy>
   <!-- 拷贝contexts到目标路径 -->
   <copy todir="${build.contexts}">
    <fileset dir="${src.contexts}"/>
   </copy>
   <!-- 拷贝conf到目标路径 -->
   <copy todir="${build.conf}">
    <fileset dir="${src.conf}"/>
   </copy>
</target>

<!-- 拷贝交通银行配置文件到目标路径 -->
<target name="resources_jtyh_copy" depends="init" description="copy the jtyh config files">
   <copy todir="${build.conf}" includeEmptyDirs="no" overwrite="true">
    <fileset dir="${src.test.resources_jtyh.dir}">
     <patternset>
      <include name="*.properties" />
      <include name="*.xml" />
      <include name="*.dtd" />
     </patternset>
    </fileset>
   </copy>
</target>
<!-- 拷贝网关版配置文件到目标路径 -->
<target name="resources_gateway_copy" depends="init" description="copy the gateway config files">
   <copy todir="${build.conf}" includeEmptyDirs="no" overwrite="true">
    <fileset dir="${src.test.resources_gateway.dir}">
     <patternset>
      <include name="*.properties" />
      <include name="*.xml" />
      <include name="*.dtd" />
     </patternset>
    </fileset>
   </copy>
</target>
<!-- 拷贝太平洋保险配置文件到目标路径 -->
<target name="resources_tpybx_copy" depends="init" description="拷贝太平洋保险配置文件">
   <copy todir="${build.conf}" includeEmptyDirs="no" overwrite="true">
    <fileset dir="${src.test.resources_tpybx.dir}">
     <patternset>
      <include name="*.properties" />
      <include name="*.xml" />
      <include name="*.dtd" />
     </patternset>
    </fileset>
   </copy>
</target>
<!-- 拷贝国泰君安配置文件目录路径 -->
<target name="resources_gtja_copy" depends="init" description="拷贝国泰君安配置文件">
   <copy todir="${build.conf}" includeEmptyDirs="no" overwrite="true">
    <fileset dir="${src.test.resources_gtja.dir}">
     <patternset>
      <include name="*.properties" />
      <include name="*.xml" />
      <include name="*.dtd" />
     </patternset>
    </fileset>
   </copy>
</target>
<!-- 执行build操作 -->
<!--target name="build" depends="init,compile,classes_jar,lib_copy,resources_copy"/-->

<!-- 执行标准平台build操作 -->
<target name="build_standardsm" depends="init,compile_test,classes_jar_test,lib_copy,resources_copy" />

<!-- 执行交通银行build操作 -->
<target name="build_jtyh" depends="build_standardsm,resources_jtyh_copy" />

<!--执行网关buil操作-->
<target name="build_gateway" depends="build_standardsm,resources_gateway_copy" />

<!--执行太平洋保险build操作-->
<target name="build_tpybx" depends="build_standardsm,resources_tpybx_copy" />

<!--执行国泰君安build操作-->
<target name="build_gtja" depends="build_standardsm,resources_gtja_copy" />
<!-- 执行代码混淆,只混淆lib/tech_*.jar -->
<target name="obfuscate">
   <!--初始化混淆目标路径-->
   <delete dir="${build_lib_obfuscate.dir}" />
   <mkdir dir="${build_lib_obfuscate.dir}" />
   <!--引入proguard task-->
   <taskdef resource="proguard/ant/task.properties" />
   <!--执行混淆-->
   <proguard ignorewarnings="true" configuration="library.pro">
    <injar path="${build_lib.dir}" jarfilter="tech_*.jar" />
    <outjar file="${build_lib_obfuscate.dir}" />
    <libraryjar file="${build_lib.dir}" />
    <libraryjar file="${java.home}/lib/rt.jar" />
    -printmapping ${build.dir}/obfuscation.map
   </proguard>
   <!--混淆后的jar覆盖原有jar -->
   <copy todir="${build_lib.dir}" overwrite="true">
    <fileset dir="${build_lib_obfuscate.dir}" />
   </copy>
</target>

</project>

【上篇】
【下篇】

抱歉!评论已关闭.