Your SlideShare is downloading. ×
ANT
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

ANT

557
views

Published on

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
557
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Ant, MSBuild, Shell Scripts
    8 March 2010
  • 2. What Is Ant?
    A build tool like make
    Open source
    from the Apache Jakarta project
    http://jakarta.apache.org/ant
    Implemented in Java
    Used to build many open source products
  • 3. Why Use Ant?
    Develop big programs by automating all tasks of compiling code, running tests, packaging and etc.
    Ant is more portable
    Ant only requires a Java VM
    Ant targets are described in XML
    Does not have cryptic syntax.
  • 4. How Does Ant Work?
    Ant commands (or tasks) are implemented by Java classes
    many are built-in
    others come in optional JAR files
    custom tasks can be created
    Each project using Ant will have a build file
    typically called build.xml since Ant looks for this by default
    Each build file is composed of targets
    these correspond to common activities like compiling and running code
    Each target is composed of tasks
    executed in sequence when the target is executed
    Ant targets can have dependencies
    for example, modified source files must be compiled
    before the application can be run
  • 5. How Does Ant Work? (Cont’d)
    Targets to be executed
    can be specified on the command line when invoking Ant
    if none are specified then the default target is executed
    execution stops if an error is encountered so all requested targets may not be executed
    Each target is only executed once
    for example
    the “test” and “deploy” targets both depend on “compile”
    the “all” target depends on “test” and “deploy”
    but “compile” is only executed once when “all” is executed
    Some tasks are only executed when they need to be
    for example, files that have not changed since the last time they were compiled are not recompiled
  • 6. <?xml version="1.0" ?>
    <project name="testAnt" default="run" >
    <property name="src" location="src/test" />
    <property name="output" location="build/classes" />
    <property name="msg" value="First Ant Making Directories..." />
    <target name="init">
    <echo> ${msg} </echo>
    <mkdir dir="${output}" />
    </target>
    <target name="compile" depends="init">
    <echo> Compiling... </echo>
    <javac srcdir="${src}" destdir="${output}"/>
    </target>
    Sample Build File (build.xml)
    Default target name
    Property values
    A target named by “init”
    Tasks which is executed in the sequence order
    Using property value “output”
  • 7. Sample Build File (Cont’d)
    <target name="run" depends="init,compile" >
    <java fork="true" classname="test.Main">
    <classpath>
    <pathelement location="${output}"/>
    </classpath>
    </java>
    </target>
    <target name="clean">
    <delete dir="${output}" />
    </target>
    </project>
    Means that the init,compile targets must be executed before this target
  • 8. MSBuild
    Microsoft Build Engine 
  • 9. What Is MSbuild?
    A Build tool like Ant
    Ships with Microsoft.NET Framework
    General purpose build automation system
    Uses XML-based language
    Syntax similar to Ant
  • 10. The Basic Elements
    Root container for Msbuild file (.csproj)
    <Project DefaultTargets="SampleTarget" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    </Project>
    Properties
    A property defines a value associated with a name
    <PropertyGroup>
    <OutputDirectory>Output</OutputDirectory>
    <AppName>test</AppName>
    </PropertyGroup>
    Using properties
    <Target Name="CreateDirectories“>
    <MakeDir Directories="$(MSBuildProjectDirectory)$(OutputDirectory)"/>
    </Target>
    All other elements
    Using
    property value
  • 11. The Basic Elements (cont’d)
    Items
    An item is a named reference to a file or to many files.
    Contain associated metadata, such as the full path or filename.
    <ItemGroup>
    <Compile Include="Program.cs" />
    <Compile Include=“Form.cs" />
    </ItemGroup>
    Using Items
    Reference the item collection in the example above with @(Compile)
    Accessing well known meta data of items
    syntax %(ItemMetadataName)
    Item collection named as Compile
  • 12. The Basic Elements (cont’d)
    Targets
    Is a container for related tasks that will be executed sequentially
    Equivalent to Methods
    Must have a name
    <Target Name="SampleTarget" DependsOnTargets="DepTarget">
    <Message Text="SampleTarget executed" />
    </Target>
    <Target Name=“DepTarget">
    <Message Text="DependentTarget executed " />
    </Target>
    Means that the DepTarget must be executed before this target
  • 13. The Basic Elements (cont’d)
    Tasks
    Equivalent to a Statement
    Smallest unit of execution
    Must be declared within a Target
    Many standard ones included in MSBuild
    MakeDir,Copy, Message, Csc, Exec, etc.
    Custom tasks can be created
    <Project xmlns=“http://schemas.microsoft.com/developer/msbuild/2003”>
    <Target Name="CreateDirectories">
    <MakeDir Directories=“output"/>
    </Target>
    </Project>
    Simple task which create directory called “output”
  • 14. Shell Scripts
    Windows scripting 
  • 15. About Shell Scripts
    Also called batch programs or scripts
    Contains one or more commands and has a .bat or .cmd file name extension
    for, goto, call and if, enable you to do conditional processing of the commands
    Commands are not case sensitive
    Executed by the command interpreter
  • 16. Batch Parameters
    Similar to Command line arguments
    Using Batch Parameters
    %{argument_no}
    Using modifiers with batch parameters
    echo %~f0
    How to change the position of batch parameter?
    Using SHIFT /N command
    SHIFT /2
    would shift %3 to %2 and so on, and leave %0 and %1 unaffected.
    %* Reference to all the arguments, not including %0
    Expands %0 to a fully qualified path name.
  • 17. More Information About Commands
    Call

×