10a. Advanced WebDriver – Using Apache ANT

Hiya folks! Do you have ANTs in your build? Just kidding! Actually, I am not. Agreed that it sounds weird, but don’t fear as I am here! (Now, that’s what I call, rhyming.)

Today, let us ponder about what exactly this Apache ANT is and why it takes its place as an important building block in the construction of a WebDriver framework. By the end of this post, you should be able to handle any ANT project in general.

Jumping right in:

Another Neat Tool provided by The Apache Software Foundation is a build tool written in Java. It is old (Maven is winning this space and Gradle is getting along), quite popular and can still be found in most of the projects. The beauty of Apache ANT is that it only does what it is told to do. There isn’t much magic that is happening under the hood. (Beware, this can be a double-edged sword at times!)

To create an executable would mean,

  • Compiling the required .java files under the src folder
  • Creating the Manifest file for the JAR
  • Zipping all the .class files along with the manifest file
  • Using the jar command to create the executable

But with Apache ANT all these steps can be handled with a simple Target (we will see what a Target is, in a minute!).

Everything to be achieved is specified in an XML file, in a structured and modular way making it very easy to identify if something breaks. And this file is known as the famous, “build.xml”.

Apache ANT comes with a default buildfile named, build.xml. We can always edit or create a new XML file to suit our needs. This is basically a command-line tool. So, it is very easy to run Apache ANT from the command prompt using the command, “ant build_file_name.xml”. The best part here is, in case you did not rename the build.xml (just modified the provided default or created your own and named it build.xml), then just the command, “ant” would automatically know to look for build.xml and do what it is made for!

Apache ANT gives a lot of power, enough to cross the Thank You threshold! We can,

  • Clean up the project
  • Compile source code
  • Generate a distributable JAR or WAR
  • Handle code from version control systems such as CVS, SVN etc.
  • Echo messages to loggers and listeners at a specified level (error, warning, info, verbose, debug)
  • Create or delete directories
  • Copy, move, delete files
  • Can zip, unzip, tar, untar, unjar, unwar files
  • Execute JUnit tests, test scripts etc.
  • Execute a series of SQL statements via JDBC to a database
  • Generate JUnit test report

And do much much more…

And guess what, it sounds intimidating but every single thing that I have mentioned so far can be achieved with just the buildfile.

Time to juggle with the elements of the much-hyped, buildfiles. These are written in XML.

Sticky Note: Below information is enough to get familiarized with an Apache ANT buildfile. For in depth knowledge, please visit the Apache ANT user manual. (http://ant.apache.org/manual/)

Each buildfile has,

  1. Project – contains a minimum of one Target
  2. Target – set of Tasks that perform a unit of work
  3. Task – piece of code that can be executed

Sample build.xml file is as follows,

sample build.xml

Let us distill the buildfile one tag at a time.

Project: This has three attributes.

  1. name – The name of the project
  2. default – The default target that should be executed in case nothing is provided
  3. baseDir – The base directory from which the relative paths in the file are calculated. “.” refers to the current directory from which execution takes place

Target: As shown in the sample buildfile, a project can have one or more targets. Target is a set of Tasks. We can select which targets we would like ANT to execute by their names separated by commas. When no target is specified, then the default target is executed.

The important attribute to note here is “depends”. This specifies the target name that it is dependent on. For example, the compile target will execute only after its dependent, init target is executed. Thus, depends attribute specifies the order in which targets are to be executed.

Task: This is a piece of code that can be executed. Each task can have one or more attributes as key-value pairs.


<name attribute1=”value1attribute2=”value2” … />

name is the name of the task, attributeN and valueN are the attribute and value names respectively.

Here is a long list of built-in tasks that come right out of the box. We can code our own tasks as well. (Remember? It is all written in Java).

You must be wondering, why to go so deep into buildfiles rather than just installing it straight away and start some action! There is a reason for imparting so much ANT knowledge. And you will appreciate me for that as we go further in our journey. Just wait and watch…

Down to business now!

Step 1: Go to, ‘https://ant.apache.org/bindownload.cgi’ and click on ‘apache-ant-1.10.2-bin.zip’ to download the .zip file under ‘Current Release of Ant’.

Download link

Step 2: Once the .zip archive is downloaded, extract all the files to a directory on your local machine.

Step 3: Set the environment variables, ANT_HOME and Path as follows,

Right click on ‘Computer’ -> Properties -> Advanced system settings -> ‘Advanced’ tab -> Environment Variables -> Click ‘New’ under system variables.

ANT_HOME is set to the path of the folder in which Apache ANT files are extracted.

System variable settings

Similarly edit the Path variable to include %ANT_HOME%bin.

Step 4: Verify if Apache ANT is installed by typing the following command in ‘Command Prompt’

ant -version

ANT version check in cmd

Step 5: Next task is to open Eclipse IDE,

  • Right-click on the Java project -> Export
  • Under ‘General’, select ‘Ant Buildfiles’ and click ‘Next’
  • Make sure the required project is selected
  • Uncheck ‘Create target to compile project using Eclipse compiler’ in order to remove any dependency on Eclipse

Generating ANT buildfile

Click on ‘Finish’ to see an eclipse auto-generated build.xml file.

And that’s it! You are all set to run your project as ANT build. It is laughably simple, isn’t it?

Sticky Note: Eclipse comes integrated with ANT. In order to make sure Eclipse’s ‘Ant Home’ points to the latest version of ANT, click on Windows -> Preferences -> Ant -> Runtime. Click on the ‘Classpath’ tab. Expand ‘Ant Home Entries’ and verify the path. If it is pointing to a different version, then click ‘Ant Home’ and browse the location of the folder in which Apache ANT files are extracted.

In our next post let us do just that and generate a JUnit report with the help of an ANT target.

Happy installing!

Series Navigation

<< 9z. WebDriver – Window maximize

StringBuffer toString Java Example


StringBuffer toString Java Example

This example shows how to convert StringBuffer to String in Java using

toString method of String class.



public class JavaStringBufferToStringExample {


public static void main(String args[]){

//create StringBuffer object

StringBuffer sbf = new StringBuffer(“Hello World!”);


* To convert StringBuffer to String object, use

* String toString() method of StringBuffer class.


String str = sbf.toString();

System.out.println(“StringBuffer to String: “ + str);





Output of above given StringBuffer to String example would be

StringBuffer to String: Hello World!


Energy Engineering Questions and Answers – Applications of Biogas & Gasifier

This set of Energy Engineering Multiple Choice Questions & Answers (MCQs) focuses on “Applications of Biogas & Gasifier”.

1. What is the percentage at which rated power from biogas in petrol engine can be developed?
a) 45%
b) 65%
c) 75%
d) 85%
View Answer

Answer: d
Explanation: Petrol engine can be operated on biogas after initially starting with petrol. Petrol replacement of 1005 is possible and petrol engines can develop about 85% of rated power where as diesel engine can develop full power.

2. Which engine can run on dual fuel with little engine modification?
a) Diesel engine
b) Petrol engine
c) IC engine
d) External combustion engine
View Answer

Answer: a
Explanation: Diesel engine can run on dual fuel with little engine modifications. Advancing the injection timing and entry of biogas with intake air, it can be achieved by providing a mixing chamber below the air cleaner which facilitates mixing of biogas with air before entering into the cylinder.

3. Which of the SI engine can be run on biogas?
a) Diesel engine
b) Petrol engine
c) IC engine
d) External combustion engine
View Answer

Answer: b
Explanation: Petrol engine can run on biogas, but it is required to be started with petrol in the beginning. Petrol engine can be modified for operation on biogas including provision for entry of biogas, throttling of intake air and advancing ignition timing.

4. What does CNG stands?
a) Converted natural gas
b) Compressed natural gas
c) Compressed Non-soluble gas
d) Compressed natural gasoline
View Answer

Answer: b
Explanation: Compressed natural gas (CNG) (methane stored at high pressure) is a fuel which can be used in place of gasoline (petrol), Diesel fuel and propane/LPG. CNG combustion produces fewer undesirable gases than the fuels mentioned above.

5. What is the full form of VRA?
a) Vibration resistant appliance
b) Vehicle Refueling Appliances
c) Volatile removal assembly
d) Validated requirement authority
View Answer

Answer: b
Explanation: Vehicle refueling appliance is abbreviated as VRAs. Certified natural gas compressors for refueling the vehicles are commercially available. These allow refueling at home and work. After upgrading with the above-mentioned technologies, the biogas (transformed into biomethane) can be used as vehicle fuel in adapted vehicles.

6. A device for converting substances (chemically or physically) into gas is called ______
a) Gasifies
b) Biogas plants
c) Draughts
d) Gas chambers
View Answer

Answer: a
Explanation: The word Gasification implies converting a solid or liquid into a gaseous fuel without leaving any solid carbonaceous residue. Gasifier is a equipment which can gasify a variety of biomass such as wood waste, agricultural waste like stalks, and roots of various crops. The gasifier is essentially a chemical reactor where various complex physical and chemical processes take place.

7. How many types of gasifiers are there?
a) 2
b) 3
c) 4
d) 5
View Answer

Answer: c
Explanation: There are four types of gasifiers namely:
1. Up draught or counter current gasifier.
2. Down draught or co-current gasifier.
3. Cross draught gasifier.
4. Fluidized bed gasifier.

8. Which is the oldest and simplest type of gasifier?
a) Counter current gasifier
b) Cross draught gasifier
c) Co-current gasifier
d) Fluidized bed gasifier
View Answer

Answer: a
Explanation: The oldest and simplest type of gasifier is the counter current or up draught gasifier. The major advantage of this type of gasifier are its simplicity, high charcoal burnout and internal heat exchange leading to low gas exit temperatures and high equipment efficiency.

9. Which is the gasifier that can be operated in small scale/amounts?
a) Counter current gasifier
b) Cross draught gasifier
c) Co-current gasifier
d) Fluidized bed gasifier
View Answer

Answer: b
Explanation: It is actually the advantage of this system that it is capable of handling very small amounts for operation. Installations below 10 KW can under certain conditions be economically feasible. The reason is the very simple gas cleaning train which can be employed when using this type of gasifier.

10. Which gasifier has better tar converting capacity?
a) Counter current gasifier
b) Cross draught gasifier
c) Co-current gasifier
d) Fluidized bed gasifier
View Answer

Answer: c
Explanation: A solution to the problem of tar entrainment in the gas stream has been found by designing co-current or down draught gasifiers, in which primary gasification air is introduced at or above the oxidation zone in the gasifier.

11. Which gasifier has a minimum tar converting capability?
a) Counter current gasifier
b) Cross draught gasifier
c) Co-current gasifier
d) Fluidized bed gasifier
View Answer

Answer: b
Explanation: A disadvantage of cross draught gasifiers is their minimal tar converting capacity and the consequent needs for the high quality charcoal. It is because of the uncertainty of charcoal quality that a number of charcoal gasifiers employ down draught principle, in order to maintain at least a minimal tar cracking capability.

12. Which gasifier equipment has inability to operate on a number of unprocessed fuels?
a) Counter current gasifier
b) Cross draught gasifier
c) Co-current gasifier
d) Fluidized bed gasifier
View Answer

Answer: c
Explanation: Down draught gasifier or co-current gasifiers equipment lies in its inability to operate on a number of unprocessed fuels. In particular, fluffy, low density materials give rise to flow problems and excessive pressure drop and the solid fuel must be pelletized before use.

Sanfoundry Global Education & Learning Series – Energy Engineering.

To practice all areas of Energy Engineering, here is complete set of 1000+ Multiple Choice Questions and Answers.

Source link

Java tutorials

Java tutorials are the best if you are a beginner or even an experienced programmer. The good thing with Java tutorials is that they are free on the internet what you only need is an internet connection to access them and get what you want regarding Java programming.Instead of going around shopping for books you can try Java tutorials, you will be amazed by the information you will find available online about java.Java tutorials is one of the easiest and fastest means to get information about Java tips with no cost and much hassle as many think.

Internet Java tutorials are the best even to those who are total beginners who may be wishing to learn about Java than attending to class courses. Beginners can find anything by getting started with some basic skills in the Java language, essential classes and get into more specialized tutorials such as graphics, security in Java, how to work with databases and many more. There are so many websites online today that are specialized in giving Java tutorials and tips to all those who may need them. They were written by experts and then placed in different categories where they fall at for easy access. The best thing to do to understand is reading more tutorials that you come across and than combine them with the useful and short Java tips you find.
For the experienced programmers, you should share your knowledge with the newbies by writing Java tips and tutorials to help those who may need them.
All you should ensure at large when writing Java tutorials are making yourself clear and understood. You should also ensure you cover all the aspects of the problem you are writing. There are some rules you should also follow if you need people to find and understand all information you are delivering efficiently. Some of the rules are such like choosing an interesting title for your Java tip. The title should capture what you are exactly presenting. Your writing should also be accompanied by the best subtitle which will expand a little bit on what you are writing about. You can also if you wish a short and precise comment or summary to describe what your Java tips do. After completing all these, you go directly to the introduction, code listing of your Java tip, write an explanation for your tip and finally end with a conclusion. You can also add a link to direct your readers to more detailed Java tutorials on the particular subject you are writing. Java tips and tutorials are the best learning resources and improving skills in Java.