More Tutorials| Bioinformatics| Open Source| Photoshop| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Executes a Java class within the Ant VM 
 

This example illustrates how to call class file through build.xml file.

 

Executes a Java class within the Ant VM

                         

This example illustrates how to call class file through build.xml file. The build.xml file is used to compile and run the java file and print the calculated value on command prompt. Here we are using only four targets, "clean" target deletes any previous "build" directory; second one is used to create "build" and "src" directories which depend on <target name="clean">, after execution of the clean target, this target will be executed; third one is used to compile the java file from "src" directory, it transforms source files in to object files in the appropriate location in the build directory and it depends on <target name="prepare">; forth one is used to run the class file and it depends on <target name="compile">. The debug keyword is used to find the error and optimize is used to find resources of source and destination directory. In the target run, fork="true" is used to display output and failonerror is used to display error report. 

 

 

<?xml version="1.0"?>
<project name="add" default="run" basedir=".">

  <target name="clean">
    <delete dir="build"/>
  </target>

  <target name="prepare" depends="clean">
    <mkdir dir="src"/>
    <mkdir dir="build"/>
  </target>

  <target name="compile" depends="prepare">
    <javac srcdir="src" destdir="build" debug="on" optimize="on"/>      
  </target>

  <target name="run" depends="compile">
    <java fork="true" failonerror="yes" classname="Addition" classpath="build">  
      <arg line=""/>
    </java>
  </target>

</project>


Simply copy and paste the following source code in the src directory and then run with ant command. The following output will be displayed:

class Addition{
        public static void main(String[] args) {
                int a=5;
                int b=10;
                int add = a + b;
                System.out.println("Addition = " + add);
        }
}



Download Source Code

                         

» View all related tutorials
Related Tags: sql c database xml file url data ui build property user sed password word driver vi name using this element

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.