4.3 Script a build in Ant

Learning Objectives

By the end of this lesson you will be able to:

EXERCISE: Run Ant build

  1. From the AWSCLI, install using yum
    $ sudo yum -y install ant
    			  
  2. Go to the build directory.
    cd /home/ec2-user/continuous_integration_example/software/build
  3. Type ant from the command line
    ant
    You should receive a message like this:
    Buildfile: build.xml does not exist!
    Build failed
  4. From the build directory, create an Ant build file called myantbuild.xml
    $ sudo vim myantbuild.xml
      
  5. Create an Ant project within the myantbuild.xml file
    <?xml version="1.0" encoding="iso-8859-1"?>
    <project name="mybuild" default="all" basedir=".">
    	
    </project>
    
  6. Define properties between the project tags.
    	
    <property name="classes.dir" value="classes"/>
    <property name="src.dir" value="src"/>
      
  7. Define targets after the property definitions
    	
    <target name="all">
    </target>
    
    <target name="compile-src">
    </target>
      
  8. Add tasks to targets (within the compile-src target)
    <javac destdir="${classes.dir}" debug="true">
      <mkdir dir="${classes.dir}"/>
      <src path="${src.dir}" />
      <classpath refid="project.class.path"/>
    </javac>
      
  9. Define dependent targets
    <target name="all" depends="compile-src">
  10. The entire myantbuild.xml file should look like this:
    	
    <?xml version="1.0" encoding="iso-8859-1"?>
    <project name="mybuild" default="all" basedir=".">
    
      <property name="classes.dir" value="classes"/>
      <property name="src.dir" value="src"/>
    
      <path id="project.class.path">
        <pathelement location="." />
        <pathelement location="${classes.dir}" />
      </path>
    
      <target name="all" depends="compile-src">
      </target>
    
      <target name="compile-src">
        <mkdir dir="${classes.dir}"/>
        <javac destdir="${classes.dir}" debug="true">
          <src path="${src.dir}" />
          <classpath refid="project.class.path"/>
        </javac>
      </target>
    </project>	
      
  11. Run myantbuild.xml file from the command line
    $ ant -f myantbuild.xml
      
  12. Add the file in Git
    $ git add .
    	
  13. Commit the file to Git
    $ git commit -m "Modified build script"
    	
  14. Push it to the Git master.
    $ git push
    	  

EXERCISE: Create a Rake build script (OPTIONAL)

  1. From your AWSCLI instance go to sample_app, open some build scripts.
  2. $ cd /home/ec2-user/sample_app/
    					
    $ sudo vim Rakefile
    					
    Open the build tasks.
    $ cd /home/ec2-user/sample_app/lib/tasks
    					
    $ sudo vim sample_data.rake
    					
  3. You can also find these files by going to https://github.com/stelligent/sample_app/blob/master/Rakefile and https://github.com/stelligent/sample_app/blob/master/lib/tasks/sample_data.rake.
  4. Make a modification to the contents of the file and save it.
  5. Add the file in Git
    $ git add .
    						
  6. Commit the file to Git
    $ git commit -m "Modified build script"
    						
  7. Push it to the Git master.
    $ git push