Ant系列九:使用Ant将java工程打包成bat可执行性文件 .

转自: http://blog.csdn.net/aerchi/article/details/7175835

在elicpse下,使用ant对java进行打包,使其生成一个XXX.bat的可执行性文件

核心代码如下:

 

build.properties(存放的是自定义的属性)

 

 

Java代码   收藏代码
  1. build=build   
  2. build.test=build/test  
  3. build.test.classes=build/test/classes  
  4. lib=lib  
  5. main.src=src  
  6. test.bat=build/test/test.bat  
  7. test.bat.template=test.bat.template  

 

 

test.bat.template(bat的脚步语言)

 

 

Java代码   收藏代码
  1. @echo off  
  2. REM  
  3. REM Copyright (c) 2009 BES Tech Service(HK) Co., Ltd.  All rights reserved.  
  4. REM  
  5. setlocal  
  6. java  -cp "mysql-connector-java-5.0.8-bin.jar";"commons-pool-1.2.jar";"commons-dbutils-1.0.jar";"commons-dbcp-1.2.1.jar";"dom4j-1.6.1.jar";"log4j-1.2.15.jar";"commons-io-1.3.2.jar";"commons-lang-2.3.jar";"classes/" my.RunMain  %*  
  7. cmd /k  
  8. endlocal  

 

 

build.xml(具体的操作)

 

 

Java代码   收藏代码
  1. <!--   
  2.     project中属性说明:  
  3.     (1default表示默认的运行目标,这个属性是必须的。   
  4.     (2) basedir表示项目的基准目录。   
  5.     (3) name表示项目名。   
  6.     (4) description表示项目的描述    
  7. -->  
  8. <project name="antBatTest" default="all" basedir=".">  
  9.     <!-- 加载属性文件,所有的自定义属性都包含在build.properties里面-->  
  10.     <property file="./build.properties" />  
  11.   
  12.     <!-- 依次执行clean,compile,assembly,publish 任务-->  
  13.     <target name="all" depends="clean,init,compile,assembly,publish">  
  14.     </target>  
  15.     <!-- 初始化,生成主要的目录-->  
  16.     <target name="init">  
  17.         <mkdir dir="${build}" />  
  18.         <mkdir dir="${build.test.classes}" />  
  19.         <path id="platform.classpath">  
  20.             <fileset dir="${lib}">  
  21.             </fileset>  
  22.         </path>  
  23.     </target>  
  24.     <!-- 编译src下的java文件-->  
  25.     <target name="compile">  
  26.         <javac destdir="${build.test.classes}" source="1.5" failοnerrοr="true" encoding="UTF-8">  
  27.             <src path="${main.src}" />  
  28.             <classpath refid="platform.classpath" />  
  29.         </javac>  
  30.   
  31.     </target>  
  32.     <!--拷贝非java文件到classes下-->  
  33.     <target name="assembly">  
  34.         <copy todir="${build.test.classes}">  
  35.             <fileset dir="${main.src}">  
  36.                 <exclude name="**/*.java" />  
  37.             </fileset>  
  38.         </copy>  
  39.     </target>  
  40.     <!--发布-->  
  41.     <target name="publish">  
  42.         <mkdir dir="${build}" />  
  43.         <mkdir dir="${build.test}" />  
  44.         <mkdir dir="${build.test.classes}" />  
  45.         <!--写入bat的脚步语句 -->  
  46.         <copy file="${test.bat.template}" tofile="${test.bat}" overwrite="true" />  
  47.         <!-- 拷贝lib下所有的jar包到${build.test}目录下 -->  
  48.         <copy todir="${build.test}" overwrite="true">  
  49.                     <fileset dir="${lib}">  
  50.                         <include name="**/*"/>  
  51.                     </fileset>  
  52.                 </copy>  
  53.     </target>  
  54.   <!--清除build下的文件-->  
  55.     <target name="clean">  
  56.         <delete dir="${build}" />  
  57.     </target>  
  58.   
  59. </project>  

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值