Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide


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