运用Ant编译Java程序的一个小实例

1. native2ascii.bat文件内容:
 
@echo off
@setlocal
set JAVA_HOME=%JDK6_HOME%
if "%JAVA_HOME%" == "" goto noJavaHome
 
SET CMD=%JAVA_HOME%\bin\java -Xms256m -Xmx512m -cp build\lib\ant.jar;build\lib\optional.jar;%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%
\jre\lib\rt.jar org.apache.tools.ant.Main
 
SET BUILD=%CMD% -buildfile native2ascii.xml
 
if "X%1"=="Xnative" goto native
 
:native
%BUILD% -propertyfile build.properties native
goto mainEnd
 
:noJavaHome
echo.
echo Warning: JAVA_HOME environment variable is not set.
echo   If build fails because sun.* classes could not be found
echo   you will need to set the JAVA_HOME environment variable
echo   to the installation directory of java.
echo.
 
:mainEnd
@endlocal
 
2. native2ascii.xml文件内容:
<?xml version="1.0" encoding="UTF-8"?>
<project name="MIT" default="native" basedir=".">
    <property name="dist.dir" value="./dist"/>
    <property name="webapp.dir" value="./web"/>
    <target name="native" >
        <echo message="Convert Resource Files"/>
        <!-- Convert Resource Files -->
        <native2ascii encoding="ISO-8859-1" src="${webapp.dir}/WEB-INF/classes/resources/en_US" dest="${dist.dir}/classes" includes="*.properties"/>
        <native2ascii encoding="GBK" src="${webapp.dir}/WEB-INF/classes/resources/zh_CN" dest="${dist.dir}/classes" includes="*.properties"/>
        <native2ascii encoding="GBK" src="${webapp.dir}/WEB-INF/classes/resources/zh_TW" dest="${dist.dir}/classes" includes="*.properties"/>
        <native2ascii encoding="ISO-8859-1" src="${webapp.dir}/WEB-INF/classes/resources/nl_NL" dest="${dist.dir}/classes" includes="*.properties"/>
        <native2ascii encoding="EUC-JP" src="${webapp.dir}/WEB-INF/classes/resources/ja_JP" dest="${dist.dir}/classes" includes="*.properties"/>       
    </target>
</project>
 
3. <project>元素有个default属性,指定默认执行的target。即在执行native2ascii批处理文件时没有传入任何参数,则默认执行default中指定的任务。
 
4. 批处理中参数的传递
(1) 命令
D:\dev\RB-2.1.x-gx>native2ascii
是运行D:\dev\RB-2.1.x-gx目录下的native2ascii.bat文件
 
(2)命令行中输入:native2ascii native
往批处理文件native2ascii.bat中传入参数native。
在给出的native2ascii.bat文件中,当传入native参数,批处理程序会根据
if "X%1"=="Xnative" goto native
找到批处理块:
:native
%BUILD% -propertyfile build.properties native
goto mainEnd
然后执行:
%BUILD% -propertyfile build.properties native
命令,这条命令里的native,是传递给native2ascii.xml文件的参数,用于指定执行native2ascii.xml文件的哪个target。如果没有这个参数,则默认执行native2ascii.xml文件中<project>元素的default属性指定的target。
 
 
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值