Apache ANT Tutorial
Apache ANT Resources
Selected Reading
- ANT - Listeners and Loggers
- ANT - Custom Components
- ANT - Using If Else arguments
- ANT - Using Command Line Arguments
- ANT - Using Token
- ANT - Extending Ant
- ANT - JUnit Integration
- ANT - Eclipse Integration
- ANT - Executing Java code
- ANT - Deploying Applications
- ANT - Packaging Applications
- ANT - Create WAR Files
- ANT - Creating JAR files
- ANT - Build Documentation
- ANT - Building Projects
- ANT - Data Types
- ANT - Property Files
- ANT - Property Task
- ANT - Build Files
- ANT - Environment Setup
- ANT - Introduction
- ANT - Home
Apache ANT Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
ANT - Executing Java code
Ant - Executing Java code
You can use Ant to execute the Java code. In the following example, the java class takes in an argument (administrator s email address) and send out an email.
pubpc class NotifyAdministrator { pubpc static void main(String[] args) { String email = args[0]; notifyAdministratorviaEmail(email); System.out.println("Administrator "+email+" has been notified"); } pubpc static void notifyAdministratorviaEmail(String email { //...... } }
Here is a simple build that executes this java class.
<?xml version="1.0"?> <project name="sample" basedir="." default="notify"> <target name="notify"> <java fork="true" failonerror="yes" classname="NotifyAdministrator"> <arg pne="admin@test.com"/> </java> </target> </project>
When the build is executed, it produces the following outcome −
C:>ant Buildfile: C:uild.xml notify: [java] Administrator admin@test.com has been notified BUILD SUCCESSFUL Total time: 1 second
In this example, the java code does a simple thing which is, to send an email. We could have used the built in the Ant task to do that.
However, now that you have got the idea, you can extend your build file to call the java code that performs comppcated things. For example: encrypts your source code.
Advertisements