Hello World

Apache Ant · Wikibooks

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From Wikibooks, under CC BY-SA 4.0, as the source states it. This page at Wikibooks.

    Hello World

    Hello World in Ant

    Create a directory "My Project". Use a text editor such as Kate, Gedit or Notepad to create a file called build.xml within directory "My Project":

       <?xml version="1.0"?>
       <project name="My Project" default="hello">
           <target name="hello">
              <echo>Hello World!</echo>
           </target>
       </project>
    

    The first line in the file is flush left (no indentation). It tells ant that this is an XML file:

      <?xml version="1.0"?>
    

    The next line names the (required) project "My Project" and its default target "hello":

      <project name="My Project" default="hello">
    

    The central three lines name and define the only target ("hello") and task ("echo") in the file:

          <target name="hello">
             <echo>Hello World!</echo>
          </target>
    

    You can now open a shell and cd to the "My Project" directory you created and type "ant"

    Output of Hello World

      Buildfile: build.xml
      
      hello: 
         [echo] Hello World!
      
      Build Successful
      Total time 0 seconds
    

    Variations

    Try changing the echo line to be the following:

      <echo message="Hello There!"></echo>
    

    What is the result? Try the following also:

    <echo message="Hello There!"/>
    

    Next Section