Use Ant to compile a small Java program instance

Source: Internet
Author: User

1. Content of the native2ascii. bat file:
 
@ 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 cocould 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. Content of the native2ascii. xml file:
<? 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 "primary des = "*. properties "/>
<Native2ascii encoding = "GBK" src = "$ {webapp. dir}/WEB-INF/classes/resources/zh_CN "dest =" $ {dist. dir}/classes "primary des = "*. properties "/>
<Native2ascii encoding = "GBK" src = "$ {webapp. dir}/WEB-INF/classes/resources/zh_TW "dest =" $ {dist. dir}/classes "primary des = "*. properties "/>
<Native2ascii encoding = "ISO-8859-1" src = "$ {webapp. dir}/WEB-INF/classes/resources/nl_NL "dest =" $ {dist. dir}/classes "primary des = "*. properties "/>
<Native2ascii encoding = "EUC-JP" src = "$ {webapp. dir}/WEB-INF/classes/resources/ja_JP "dest =" $ {dist. dir}/classes "primary des = "*. properties "/>
</Target>
</Project>
 
3. The <project> element has a default attribute that specifies the target to be executed by default. That is, if no parameter is input when native2ascii batch file is executed, the task specified in default is executed by default.
 
4. Passing parameters in Batch Processing
(1) command
D: \ dev \ RB-2.1.x-gx> native2ascii
Is the native2ascii. bat file running the D: \ dev \ RB-2.1.x-gx directory
 
(2) Enter native2ascii native in the command line.
Input the native parameter to the batch file native2ascii. bat.
In the given native2ascii. bat file, when the native parameter is passed in, the batch processing program will
If "X % 1" = "Xnative" goto native
Find the batch processing block:
: Native
% BUILD %-propertyfile build. properties native
Goto mainEnd
Then execute:
% BUILD %-propertyfile build. properties native
The native in this command is a parameter passed to the native2ascii. xml file, which is used to specify the target of the native2ascii. xml file. If this parameter is not specified, the default attribute of the <project> element in the native2ascii. xml file is executed by default.
 
Author: csz_363874279qqcom

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.