Скачать презентацию
Идет загрузка презентации. Пожалуйста, подождите
Презентация была опубликована 8 лет назад пользователемАлександр Деревянко
1 1 © Luxoft Training 2012 ANT introduction
2 2 © Luxoft Training 2012 Build tools When developing software, a developer must solve routine tasks such as: Compile initial modules Carry out unit testing Give folder structure to compiled modules Archive them Copy necessary resources to modules
3 3 © Luxoft Training 2012 ANT Build Build with open-source code Java based ANT is an open-source project
4 4 © Luxoft Training 2012 ANT Build ANT is a Java program Start main Java class ANT includes a set of command files facilitating ANT launch Key parameter of command file is build file name Starting ANT
5 5 © Luxoft Training 2012 ANT Build ANT uses build file written in XML If build file name is not specified, than it is given default name build.xml File describes required sequence of actions Build script
6 6 © Luxoft Training 2012 ANT Build Starting ANT C:\work>ant C:\work>ant –buildfile custom.xml
7 7 © Luxoft Training 2012 ANT Build Script should (optionally) describe XML prologue Build script is XML document … build.xml The version prologue attribute is required The encoding attribute defines encoding
8 8 © Luxoft Training 2012 ANT Build Build script structure … … … build.xml project
9 9 © Luxoft Training 2012 ANT Build Project consists of set of targets Target defines what must be done Project can have several targets, e.g.: Compile to a certain folder Archive it and delete source classes Locate archives in specified folders Build script structure, targets
10 10 © Luxoft Training 2012 ANT Build By default, targets are handled independently If necessary, targets interrelations can be indicated When launching ANT, you can specify a certain target or select default target in the build script Build script structure, targets
11 11 © Luxoft Training 2012 ANT Build Build script structure slide 2-11 … … … build.xml project target
12 12 © Luxoft Training 2012 ANT Build Target is a sequence of tasks Task defines the way it should be done Standard nested tasks: Copy/Move/Delete Compilation (javac) Archiving (jar) New tasks can be added as far as ANT is extensible Build script structure, tasks
13 13 © Luxoft Training 2012 ANT Build Build script structure … … … build.xml project target task target task target task
14 14 © Luxoft Training 2012 ANT Build Launching certain target C:\work>ant C:\work>ant archive Command line
15 15 © Luxoft Training 2012 ANT Build Working with file system Compiling Java classes Archiving to jar archive Starting Java and OS programs The most common tasks
16 16 © Luxoft Training 2012 ANT Build Conclusion on build script … … … build.xml
17 17 © Luxoft Training 2012 Installing ANT Download installation package from Installation package is a zip archive Unpack it Include bin folder to the variable of PATH environment, to start ANT from any file system location slide3-17 ANT is an open software
18 18 © Luxoft Training 2012 Installing ANT Checking ANT installation
19 19 © Luxoft Training 2012 Starting ANT Getting help in ANT
20 20 © Luxoft Training 2012 Starting ANT Key parameter is build file; if it is not indicated, then name is build.xml Build filename can be specified by parameters -buildfile -file -f Parameters
21 21 © Luxoft Training 2012 Starting ANT The following startup parameters affect ANT displaying: -diagnostics -quiet -verbose -debug -log filename ANT build displaying parameters
22 22 © Luxoft Training 2012 Build script Target dependencies, option 1 … … … build.xml If target B depends on target A, then when target B is invoked, target A is run automatically
23 23 © Luxoft Training 2012 Build script Target dependencies, option 2 … … … build.xml
24 24 © Luxoft Training 2012 Build script Target dependencies
25 25 © Luxoft Training 2012 Build script Frequently, build file contains the most popular target To avoid specifying its name every time when build is started, developer can define default target Default target
26 26 © Luxoft Training 2012 Build script Default target … … … build.xml
27 27 © Luxoft Training 2012 Build script Default target
28 28 © Luxoft Training 2012 Build script Sometimes we need to specify directory that differs from the default To specify directory use basedir attribute of the project Path directory … build.xml
29
29 © Luxoft Training 2012 Build script Comments …
30 30 © Luxoft Training 2012 Build script Project help
31 31 © Luxoft Training 2012 Build File Properties Properties are named constants Having set the property value once only, developer can refer to it any time by its name Properties facilitate portability and supportability of build files Properties
32 32 © Luxoft Training 2012 Build File Properties Developer can set build file properties Special element is provided for that Setting script properties To refer to property use this syntax: ${ property_name }
33 33 © Luxoft Training 2012 Build File Properties Using properties ${ message } build.xml
34 34 © Luxoft Training 2012 Build File Properties Using properties
35 35 © Luxoft Training 2012 Build File Properties It is not always convenient to set properties directly in script, because it decreases scripts supportability and portability You can set properties: In build file In external file As JVM properties when launching ANT Setting properties
36 36 © Luxoft Training 2012 Build File Properties You can refer to external properties file from build file Properties file syntax: Setting properties in external file property1=value1 property2=value2 property3=value3 … *.properties
37 37 © Luxoft Training 2012 Build File Properties Setting properties in external file ${ message } build.xml
38 38 © Luxoft Training 2012 Build File Properties JVM properties are « key-value » pairs available in Java program and JVM They are set when Java program is launched by the –D option Setting properties in external file as JVM properties C:\work>java –D property_name = value MyClass Command line
39 39 © Luxoft Training 2012 Build File Properties Setting script properties as JVM properties ${ message } build.xml
40 40 © Luxoft Training 2012 Build File Properties Properties can be set: In build file In external file As JVM properties when launching ANT What is the priority of each option of properties setting? What is the difference between loading properties from file via the element and the –propertyfile key? Priorities in setting the properties
41 41 © Luxoft Training 2012 Build File Properties The highest priority As JVM properties when launching ANT Priority of place of property setting: In build file In external file Priorities in setting the properties Property value is set according to the first definition, regardless where it was done, in script or in external file
42 42 © Luxoft Training 2012 Build File Properties ANT has built-in properties: Built-in ANT properties ant.file The absolute path of the build file ant.home Home directory of ANT ant.java.version The JVM version ant.project.name The name of the project that is currently executing ant.version The ANT version basedir Projects base directory
43 43 © Luxoft Training 2012 Build Errors By default, ANT stops when it detects the first build file error This can be bypassed with the help of attributes below. When doing this, all correct tasks will be executed: -keep-going -k ANT Stop
44 44 © Luxoft Training 2012 Build Errors ANT Stop
45 45 © Luxoft Training 2012 Build Errors ANT does not provide for automatic file rollback when an error occurs Developers should implement special listeners for overall error handling ANT Stop
build.xml Default value for input pro" title="46 © Luxoft Training 2012 The most popular ANT tasks ANT task allows inputting data from console Data input from console build.xml Default value for input pro" class="link_thumb"> 46 46 © Luxoft Training 2012 The most popular ANT tasks ANT task allows inputting data from console Data input from console build.xml Default value for input properties can be defined Input can be blocked by the –noinput key when ANT is launched build.xml Default value for input pro"> build.xml Default value for input properties can be defined Input can be blocked by the –noinput key when ANT is launched"> build.xml Default value for input pro" title="46 © Luxoft Training 2012 The most popular ANT tasks ANT task allows inputting data from console Data input from console build.xml Default value for input pro">
47 47 © Luxoft Training 2012 The most popular ANT tasks ANT task the allow automating the process of document creation ANT task the is wrapper for javadoc tool from JDK JavaDoc Documenting
48 48 © Luxoft Training 2012 The most popular ANT tasks Example of Java code with JavaDoc comments JavaDoc Documenting /** This application prints out "No worries." */ public class Project { public static void main(String args[]) { System.out.println("No worries."); } Project.java
Project API ]]> Copyr" title="49 © Luxoft Training 2012 The most popular ANT tasks Documenting in ANT scripts JavaDoc Documenting
50 50 © Luxoft Training 2012 The most popular ANT tasks Build number support
51 51 © Luxoft Training 2012 The most popular ANT tasks You can add prefixes for all parameters set Properties values can be freely edited Binding to the date and time ${TODAY} ${DSTAMP} ${TSTAMP} build.xml Variables TODAY, DSTAMP, TSTAMP are created
52 52 © Luxoft Training 2012 The most popular ANT tasks Binding to the date and time
53 53 © Luxoft Training 2012 The most popular ANT tasks ANT task the creates directories Creating directories build.xml Does nothing if the directory already exists
54 54 © Luxoft Training 2012 The most popular ANT tasks ANT task the deletes directories and files Deleting directories and files build.xml
55 55 © Luxoft Training 2012 The most popular ANT tasks and tasks allow to determine directory path and local file name from composite file name The result is saved to specified property Working with composite file name build.xml
task does not copy directories. For that you should use file ma" title="56 © Luxoft Training 2012 The most popular ANT tasks The task allows copying files Copy files build.xml
57
57 © Luxoft Training 2012 The most popular ANT tasks task moves files and directories Moving files and directories build.xml
build.xml It is possible to specify File Sets and th" title="58 © Luxoft Training 2012 The most popular ANT tasks task is a wrapper for Java compiler Java code compilation
59
59 © Luxoft Training 2012 The most popular ANT tasks Setting compiler options Java code compilation
60 60 © Luxoft Training 2012 The most popular ANT tasks task allows archiving file sets to jar archive The jar utility exploits usual zip algorithm However, it adds at the same time so called manifest It is also possible to sign the archive with electronic signature Jar archiving
61 61 © Luxoft Training 2012 The most popular ANT tasks Jar archiving build.xml
62
62 © Luxoft Training 2012 The most popular ANT tasks allows running necessary Java class Running Java programs
63 63 © Luxoft Training 2012 The most popular ANT tasks Conclusions echo Input/output input javadoc Documenting buildnumber Build number tracking, versioning tstamp mkdir Working with file system delete copy move basename Working with file names dirname javac Compilation jar Archiving java Running
64 64 © Luxoft Training 2012 The most popular ANT tasks Task that were not covered
65 65 © Luxoft Training 2012 File and directory sets Their main task is to flexibly define file and directory sets Path patterns (masks, patterns) are used for that purpose Fileset and Dirset Data Types
66 66 © Luxoft Training 2012 File and directory sets Fileset type is formed by: Root directory Include sets Exclude sets Fileset Data Type build.xml
67 67 © Luxoft Training 2012 File and directory sets Masks used for definition of file set: ? any single symbol * any symbol set ** any symbol set in current directory and in sub directories (directory structure is maintained) Fileset, using masks
68 68 © Luxoft Training 2012 File and directory sets Fileset, Example 1 What will get to the test directory? build.xml The test directory will be created if there is anything to copy
69 69 © Luxoft Training 2012 File and directory sets Fileset, example 2 What will get to the test directory? build.xml
70 70 © Luxoft Training 2012 File and directory sets Fileset, example 3 What will get to the test directory? build.xml
71 71 © Luxoft Training 2012 File and directory sets Default excludes Fileset **/*~**/#*# **/.#***/%*% **/._***/CVS **/CVS/****/.cvsignore **/SCCS**/SCCS/** **/vssver.scc**/.svn **/.svn/****/.DS_Store
72 72 © Luxoft Training 2012 File and directory sets Useful attributes of fileset Fileset casesensitive File patterns are treated in a case sensitive way (true) defaultexcludes Whether default excludes shall be used or not (true) excludes s ub-element analogue excludesfile External file with a list of excluded patterns file A shortcut for specifying a single-file fileset (mutually exclusive property with dir ) followsymlinks Shall symbolic links be followed? (Unix) includes s ub-element analogue includesfile External file with a list of included patterns
73 73 © Luxoft Training 2012 File and directory sets Using Fileset, example 1 build.xml
74
74 © Luxoft Training 2012 File and directory sets Using Fileset, example 2 build.xml
75 75 © Luxoft Training 2012 File and directory sets Using Fileset, example 3 build.xml
76 76 © Luxoft Training 2012 Conditional Target Execution For that, use if and unless attributes of target element The condition for identifying the specified property in build file will act as a condition It is possible to specify conditions of target execution:
77 77 © Luxoft Training 2012 Conditional Target Execution Condition of target execution, if attribute build.xml The to_arhive property can be set both as target-scoped for other targets and as JVM property at ANT launch if to_archive property is set then the target will get executed
78 78 © Luxoft Training 2012 Conditional Target Execution Condition of target execution, unless attribute build.xml unless is opposite to if Target is executed if property is not set
79 79 © Luxoft Training 2012 Specifying Conditions Condition is a logical function of the set of variables Condition result is whether the property shall be set or not Condition variables are other properties and external factors Conditions are particularly useful in conditional target execution Conditions
80 80 © Luxoft Training 2012 Predicates and Logical AND or Logical OR not Logical NOT available The file exists or is available contains Specified string contains specified substring equals Specified strings are equal filesmatch Specified files contain matching data isset Specified property is set uptodate Specified file is older than other elsewhere Specifying Conditions
81 81 © Luxoft Training 2012 Examples of conditions Specifying Conditions
82 82 © Luxoft Training 2012 Examples of conditions Specifying Conditions
83
83 © Luxoft Training 2012 Specifying Conditions Availability condition Apart from predicate there is similar ANT task Predicate and target syntax:
84 84 © Luxoft Training 2012 Build Interruption When conditions and conditional target execution is used, it may be required to stop the build For that ANT task is used The stopping condition is the condition of whether particular property is set or not Build stop
85
85 © Luxoft Training 2012 Build Interruption task syntax Build stop
86 86 © Luxoft Training 2012 Build Interruption Build stop example
87 87 © Luxoft Training 2012 Building EJB Applications Use ANT task At the task input we have: Specific deployment descriptors Basic descriptors Set of compiled EJB (*.class) Automating the Process of Building
The task " title="88 © Luxoft Training 2012 Building EJB Applications Syntax of ANT task Automating the Process of Building
89 89 © Luxoft Training 2012 Building EAR Applications Use ANT task At the task input we have: Basic deployment descriptor Set of modules( *.war, *.jar, *.rar ) Automating the Process of Building
90
90 © Luxoft Training 2012 Building EAR Applications Syntax of ANT task Automating the Process of Building
Еще похожие презентации в нашем архиве:
© 2024 MyShared Inc.
All rights reserved.