Tutorials Navigation

Tutorials :: New :: Popular :: Top Rated

Tutorials: 18,326 Categories: 12

Total Tutorial Views: 41,408,504

Apache Ant Tutorial - Executing Java code

Tutorial Name: Apache Ant Tutorial - Executing Java code  

Category: PC Tutorials

Submitted By: hoot

Date Added:

Comments: 0

Views: 271

Related Forum: PC Building Forum

Share:

You can use Ant to execute Java code. In the following example, the java class takes in an argument (administrator's email address) and sends out an email.

public class NotifyAdministrator {

public static void main(String[] args) {
String email = args[0];
notifyAdministratorviaEmail(email);
System.out.println("Administrator "+email+" has been notified");
}

public 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 line = "[email protected]"/>
</java>
</target>
</project>


When the build is executed, it produces the following outcome

C:\>ant
Buildfile: C:\build.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 - 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 complicated things, for example: encrypts your source code.

Ratings

Please take one second and rate this tutorial...

Not a Chance
1
2
3
4
5
6
7
8
9
10
Absolutely

Comments

"Apache Ant Tutorial - Executing Java code" :: Login/Create an Account :: 0 comments

If you would like to post a comment please signin to your account or register for an account.