Download presentation
Presentation is loading. Please wait.
Published byJuniper James Modified over 9 years ago
1
Live and Learn – ant
2
Resources Ant User Manual http://ant.apache.org/manual/index.html Skip the book, most of the material is right here Apache Ant 101 – DeveloperWorks http://www- 128.ibm.com/developerworks/edu/j-dw-java- apant-i.html http://www- 128.ibm.com/developerworks/edu/j-dw-java- apant-i.html Totally righteous tutorial
3
Questions from Live and Learn 1.What is the basic structure of an Ant file? 2.What's required and what's optional? 3.What is the difference between build.xml and build.properties? 4.What is the advantages/disadvantages of defining properties in build.properties instead of build.xml? 5.How do I create and destroy directories? 6.How do I define projects to run using Ant? 7.Other hints and suggestions from an expert? 8.How to do junit tasks? 9.How to do task dependencies (don't compile unless fetch got stuff)
4
Basic structure Entities: Project Targets Tasks Types Project contains tasks, which contain targets and types Implicit target contains all “top-level” targets and types is executed each time ant is invoked, even for -projecthelp
5
Minimal file
6
Sample file (unreadable) A simple Java project
7
Sample file (part 1) A simple Java project
8
Sample file (part 2) <jar destfile="${distDir}/package-${DSTAMP}.jar" basedir="${buildDir}"> <jar destfile="${distDir}/package-src-${DSTAMP}.jar“ basedir="${srcDir}"/>
9
Properties Write-once! From command line: ant -D key=value Built-in: basedir, ant.file, ant.version, ant.project.name, ant.java.version Java System properties http://java.sun.com/j2se/1.3/docs/api/java/lang /System.html#getProperties() http://java.sun.com/j2se/1.3/docs/api/java/lang /System.html#getProperties() From the Property task
10
Property task explicitly stated: pulled from a file: Java-style properties file syntax. pulled from the environment: also URL or Resource
11
Example from ExpertVoices <fail unless="env.EV_CONFIG" message="Environment variable 'EV_CONFIG' is not set"/> <property name="config_property_file“ location="properties/${env.EV_CONFIG}.build.properties"/> <available file="${config_property_file}" type="file“ property="config_property_file_present"/> <fail unless="config_property_file_present“ message="Property file '${config_property_file}' missing"/> <property name="common_property_file“ location="properties/_common.build.properties"/>
12
File Set Inline: By reference:
13
Pattern Set Inline or by reference
14
Path-like structures -simple
15
Path-like structures - complex
16
Other types Selectors Selectors are a mechanism whereby the files that make up a fileset can be selected based on criteria other than filename. Filtersets <copy file="${build.dir}/version.txt" toFile="${dist.dir}/version.txt">
17
Optional tasks Require libraries that are not supplied with Ant Put them in Ant’s lib directory, or add to the system classpath
18
Optional tasks - gotchas from http://ant.apache.org/manual/OptionalTasks/junit.html http://ant.apache.org/manual/OptionalTasks/junit.html Note: You must have junit.jar and the class files for the task in the same classpath. You can do one of: Put both junit.jar and the optional tasks jar file in ANT_HOME/lib. Do not put either in ANT_HOME/lib, and instead include their locations in your CLASSPATH environment variable. Do neither of the above, and instead, specify their locations using a element in the build file. See the FAQ for details.the FAQ
19
If – Then – Else THEN BODY EXECUTED ELSE BODY EXECUTED
20
“Subroutines” with parameters <param name="extensions_dir" value="${third_party_themes_dir}"/> <param name="destination_dir“ value="${build_wpmu_themes_dir}"/>
21
Loops <foreach target="unzip_extension" param="zip_file" inheritall="Yes">
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.