More Tutorials| Bioinformatics| Open Source| Photoshop| Questions?
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

How to set memory used by JVM in Ant

                         

This example illustrates how to set memory size of JVM (java virtual machine), when ANT (another neat tool) is used outside of java virtual machine. In this example, <property name="sourcedir"> is used to specify the location of source directory and <property name="targetdir"> is used to specify the location of target directory and <property name="librarydir"> is used to define the location of library directory. 
               

In this build.xml file, <path id="libraries"> is used to put any jar file in the lib directory. The target <target name="clean"> is used to delete the target directory and library directory from base directory. The target <target name="prepare"> is used to create the source directory, target directory and library directory and <target name="compile"> is used to compile the source code. The fork="true" is used if you don't run Java code in a separate JVM to the ant script, you can get some pretty strange errors that are difficult to diagnose. For NoClassDefFoundError, the problem was fixed by setting fork=true in the java target. The memoryMaximumSize="1024m" for the underlying VM, if using fork mode; ignored otherwise. Defaults to the standard VM memory setting. (Examples: 83886080, 81920k, or 80m) and memoryInitialSize="256m" is used for the underlying VM, if using fork mode; ignored otherwise. Defaults to the standard VM memory setting. (Examples: 83886080, 81920k, or 80m). The source code of build.xml file is as follows:    

 

<project name="MemoryMap" default="compile" basedir=".">
  <property name="sourcedir" value="${basedir}/src"/>
  <property name="targetdir" value="${basedir}/build"/>
  <property name="librarydir" value="${basedir}/lib"/>
  
  <path id="libraries">
    <fileset dir="${librarydir}">
      <include name="*.jar"/>
    </fileset>
  </path>

    <target name="clean">
        <delete dir="${targetdir}"/>
        <delete dir="${librarydir}"/>
    </target>

  <target name="prepare" depends="clean">
    <mkdir dir="${sourcedir}"/>
    <mkdir dir="${targetdir}"/>
    <mkdir dir="${librarydir}"/>
  </target>

  <target name="compile" depends="prepare">
    <javac srcdir="${sourcedir}" destdir="${targetdir}" debug="true" 
      fork="true" memoryMaximumSize="1024m" memoryInitialSize="256m">
    </javac>       
  </target>    

</project>

 

Hello.java

class Hello{
        public static void main(String args[]){
                System.out.println("Sandeep kumar suman");
        }
}


Create a class file in the 'src' folder and compile it on the console with ant command. The following output will be displayed.


Download Source Code

                         

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 
Join and Excel yourself with our Online instructor led training sessions
Training Courses
Tell A Friend
Your Friend Name

 

 
 

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.