AntPractice (1)
Revised:Huang Kai
E_mail:Hk_sz@163.com
Preface
Since the company is now finishing the unit test case, I have made some time to understand ant and JUnit technologies, the following is a collection of the essence of the director of the family (considering that the summary is based on my ideas, it may not be able to fully express the original author's ideas, so inReferenceI have listed all the URLs or books I have referenced. You may wish to read the original article if you have time ).
If you do not understand some ant parameters, see the ant theory series or the documents that come with ant.
Contents
I,AntUse instance
1.1 passAntOfCOPT taskSubmit the latest files in the current directory (by system time) to the specified directory.
1.2AntDevelopmentJavaProgram
1.3AntIntegrationJUnitAutomated Software Testing
1.4AntDevelopment and deploymentWebApplications
1.5AntPackage (Jar)Applications
1.6AntDevelopmentEJBApplications
Reference
I. Ant use instance
1.2 use ant to develop Java programs. Take helloword as an example.
1> directory structure of this instance:
D:/test main directory
/Src source program directory
/Classes compiled class file directory
First, create the test directory and SRC subdirectory on disk D.
2> Create the helloword. Java file in the SRC subdirectory. The content is as follows:
Public class helloword
{
Public static void main (string ARGs [])
{
System. Out. println ("Hello world! ");
}
}
3> Create the build. xml file in the test main directory. The content is as follows:
<? XML version = "1.0"?>
<Project default = "build" basedir = ".">
<Property name = "appname" value = "helloword"/>
<Property name = "base" value = "D:/test"/>
<Property name = "src" value = "src"/>
<Property name = "build" value = "classes"/>
<Property name = "myclasspath" value = "$ {base}/$ {build}"/>
<Target name = "build">
<Mkdir dir = "$ {build}"/>
<Javac srcdir = "$ {SRC}" destdir = "$ {build}">
<Include name = "**/*. Java"/>
</Javac>
</Target>
<Target name = "run" depends = "build">
<Exec executable = "Java">
<Arg line = "-classpath $ {myclasspath }$ {appname}"/>
</Exec>
</Target>
<Target name = "clean">
<Delete multiple deemptydirs = "true">
<Fileset dir = "$ {build}"/>
</Delete>
</Target>
</Project>
To improve program portability, we separate the property to form the build. properties file. The new build. xml file and build. properties file are as follows:
Build. properties file:
Appname = helloword
Src = SRC
Build = classes
Myclasspath =$ {basedir} // $ {build}
Build. xml file (the property part calls build. properties through file ):
<? XML version = "1.0"?>
<Project default = "build" basedir = ".">
<Property file = "build. properties"/>
<Target name = "build">
<Mkdir dir = "$ {build}"/>
<Javac srcdir = "$ {SRC}" destdir = "$ {build}">
<Include name = "**/*. Java"/>
</Javac>
</Target>
<Target name = "run" depends = "build">
<Exec executable = "Java">
<Arg line = "-classpath $ {myclasspath }$ {appname}"/>
</Exec>
</Target>
<Target name = "clean">
<Delete multiple deemptydirs = "true">
<Fileset dir = "$ {build}"/>
</Delete>
</Target>
</Project>
4> RUN ant in the test directory to view the execution result.
Run ant run and ant clean again to see what will happen ,:)