Ant工具进行jar打包样例

lib下面的包不分子目录

<project default="jar" name="Acid">

     <!-- 工程目录结构 

        project 

            |-bin 

            |-src 

            |-lib 

            |-out 

            |-build.xml 

        -->

     <property name="lib.dir" value="lib" />

     <property name="src.dir" value="src" />

     <property name="config.dir" value="config" />

     <property name="output.dir" value="build" />

     <property name="classes.dir" value="${output.dir}/classes" />

     <property name="out.config.dir" value="${output.dir}/config" />

     <property name="jarname" value="run_persit_engine.jar" />

     <property name="mainclass" value="com.tydic.entrance.HFileGeneratorEntrance" />

     <!-- 第三方jar包的路径 -->

     <path id="lib-classpath">

           <fileset dir="${lib.dir}">

                <include name="**/*.jar" />

           </fileset>

     </path>

     <!-- 1. 初始化工作,如创建目录等 -->

     <target name="init">

           <delete dir="${classes.dir}" />

           <delete dir="${output.dir}" />

           <delete dir="${out.config.dir}" />

           <mkdir dir="${classes.dir}" />

           <mkdir dir="${output.dir}" />

           <mkdir dir="${out.config.dir}" />

     </target>

     <!-- 2. 编译 -->

     <target name="compile" depends="init">

           <javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="on">

                <compilerarg line="-encoding UTF-8" />

                <classpath refid="lib-classpath" />

           </javac>

     </target>

     <!-- 3. 打包jar文件 -->

     <target name="jar" depends="compile">

           <copy todir="${output.dir}/lib">

                <!-- 将要打的jar复制进去 -->

                <fileset dir="${lib.dir}" includes="**/hive-*.jar" />

                <fileset dir="${lib.dir}" includes="**/mysql-*.jar" />

                <!-- hbase -->

                <fileset dir="${lib.dir}" includes="**/hbase-*.jar" />

                <fileset dir="${lib.dir}" includes="**/htrace-core-*.jar" />

                <!-- spring_ibatis -->

                <fileset dir="${lib.dir}" includes="**/aspectjweaver-*.jar" />

                <fileset dir="${lib.dir}" includes="**/spring.jar" />

                <fileset dir="${lib.dir}" includes="**/cglib-nodep-*.jar" />

                <fileset dir="${lib.dir}" includes="**/ibatis-*.jar" />

                

           <!--将配置文件复制到build/config下,集群的配置文件hdfs-site.xml、core-site.xml等文件不打进jar中-->

           </copy>

           <copy todir="${out.config.dir}">

                <fileset dir="${config.dir}" excludes="*-site.xml"/>

           </copy>

           <!--用于在MANIFEST.MF中标明classpath,

                Create a property containing all .jar files, 

            prefix lib/, and seperated with a space-->

           <pathconvert property="mf.classpath" pathsep=" ">

                <mapper>

                     <chainedmapper>

                           <!-- jar包文件只留文件名,去掉目录信息 -->

                           <flattenmapper />

                           <!-- add lib/ prefix -->

                           <globmapper from="*" to="lib/*" />

                     </chainedmapper>

                </mapper>

                <path refid="lib-classpath" />

           </pathconvert>

           <!-- jar文件的输出路径 -->

           <jar destfile="${output.dir}/${jarname}" basedir="${classes.dir}">

                <manifest>

                     <attribute name="Main-class" value="${mainclass}" />

                     <attribute name="Class-Path" value="${mf.classpath}" />

                </manifest>

                <fileset dir="${out.config.dir}" includes="**/*" />

                <fileset dir="${output.dir}" includes="lib/*" />

           </jar>

     </target>

</project>

 

-------------------------------------------------------------------------------------------------------------------------------------------------------------

lib下面的包分子目录:

<project default="jar" name="Acid">

       <!-- 工程目录结构 

        project 

            |-bin 

            |-src 

            |-lib 

            |-config 

            |-build.xml 

        -->

       <property name="lib.dir" value="lib" />

       <property name="src.dir" value="src" />

       <property name="config.dir" value="config" />

       <property name="output.dir" value="build" />

       <property name="classes.dir" value="${output.dir}/classes" />

       <property name="out.config.dir" value="${output.dir}/config" />

       <property name="jarname" value="run_persit_engine.jar" />

       <property name="mainclass" value="com.tydic.entrance.HFileGeneratorEntrance" />

       <!-- 第三方jar包的路径 -->

       <path id="lib-classpath">

              <fileset dir="${lib.dir}">

                     <include name="**/*.jar" />

              </fileset>

       </path>

       <!-- 1. 初始化工作,如创建目录等 -->

       <target name="init">

              <delete dir="${classes.dir}" />

              <delete dir="${output.dir}" />

              <delete dir="${out.config.dir}" />

              <mkdir dir="${classes.dir}" />

              <mkdir dir="${output.dir}" />

              <mkdir dir="${out.config.dir}" />

       </target>

       <!-- 2. 编译 -->

       <target name="compile" depends="init">

              <javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="on">

                     <compilerarg line="-encoding UTF-8" />

                     <classpath refid="lib-classpath" />

              </javac>

       </target>

       <!-- 3. 打包jar文件 -->

       <target name="jar" depends="compile">

              <copy todir="${output.dir}/lib">

                     <!-- 将要打的jar复制进去 -->

                     <fileset dir="${lib.dir}/hive" includes="hive-*.jar" />

                     <fileset dir="${lib.dir}/common" includes="mysql-*.jar" />

                     <!-- hbase -->

                     <fileset dir="${lib.dir}/hbase" includes="hbase-*.jar" />

                     <fileset dir="${lib.dir}/hbase" includes="htrace-core-*.jar" />

                     <!-- spring_ibatis -->

                     <fileset dir="${lib.dir}/spring" includes="aspectjweaver-*.jar,spring.jar,cglib-nodep-*.jar,ibatis-*.jar" />

                                         

              <!--将配置文件复制到build/config下,集群的配置文件hdfs-site.xml、core-site.xml等文件不打进jar中-->

              </copy>

              <copy todir="${out.config.dir}">

                     <fileset dir="${config.dir}" excludes="*-site.xml"/>

              </copy>

              <!--用于在MANIFEST.MF中标明classpath,

                     Create a property containing all .jar files, 

            prefix lib/, and seperated with a space-->

              <pathconvert property="mf.classpath" pathsep=" ">

                     <mapper>

                           <chainedmapper>

                                  <!-- jar包文件只留文件名,去掉目录信息 -->

                                  <flattenmapper />

                                  <!-- add lib/ prefix -->

                                  <globmapper from="*" to="lib/*" />

                           </chainedmapper>

                     </mapper>

                     <path refid="lib-classpath" />

              </pathconvert>

              <!-- jar文件的输出路径 -->

              <jar destfile="${output.dir}/${jarname}" basedir="${classes.dir}">

                     <manifest>

                           <attribute name="Main-class" value="${mainclass}" />

                           <attribute name="Class-Path" value="${mf.classpath}" />

                     </manifest>

                     <fileset dir="${out.config.dir}" includes="**/*" />

                     <fileset dir="${output.dir}" includes="lib/*" />

              </jar>

       </target>

</project>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值