Apache Ant

Ant is a Java library and command-line tool. Ant’s mission is to drive processes described in build files as targets and extension points dependent upon each other. The main known usage of Ant is the build of Java applications. Ant supplies a number of built-in tasks allowing to compile, assemble, test and run Java applications. Ant can also be used effectively to build non Java applications, for instance C or C++ applications. More generally, Ant can be used to pilot any type of process which can be described in terms of targets and tasks.

Ant is written in Java. Users of Ant can develop their own “antlibs” containing Ant tasks and types, and are offered a large number of ready-made commercial or open-source “antlibs”.

Ant is extremely flexible and does not impose coding conventions or directory layouts to the Java projects which adopt it as a build tool.

Software development projects looking for a solution combining build tool and dependency management can use Ant in combination with Ivy.

Tagged : / / / /

Introduction of Apache Ant

Apache Ant is a software tool for automating software build processes. It is similar to Make but is implemented using the Java language, requires the Java platform, and is best suited to building Java projects.

The most immediately noticeable difference between Ant and Make is that Ant uses XML to describe the build process and its dependencies, whereas Make has its Makefile format. By default the XML file is named build.xml.

Ant is an Apache project. It is open source software, and is released under the Apache Software License.

Tagged : / / / / / / / /

Apache Ant: A Build Tool

Apache Ant (or simply Ant) is an XML-based build scripting language used heavily by the Open Source community. Ant automates tasks such as compiling source code, building deployment packages and automatically checking dependencies of what items need to be updated in a build set.

Tagged : / / /

Using Ant to build J2EE Applications

Apache Ant (Another Neat Tool) is a build tool, mainly for Java projects. A build tool can be used to automate certain repetitive tasks, e.g. compiling source code, running software tests, creating jar files, javadocs, etc.

A build process typically includes:

  • the compilation of the Java source code into Java bytecode
  • creation of the .jar file for the distribution of the code
  • creation of the Javadoc documentation

Ant uses a xml file for its configuration. This file is usually called “build.xml”. Within this build file you specify the targets for ant. A target is a step which ant will perform. You also can specific dependencies. If target A depends on target B, ant will first do B and then A. Also you specify the main target. This target is the target ant will try to execute per default. If this target depends on other targets then ant will automatically perform these task first and so on and so on.

Tagged : / / / / / /

Top 5 Build Management Tools

top-5-build-management-tools
These days in software industry the process of software development very much rely upon best practices of various tools. The software development teams use various tools like project management, release management , test management and various others. As we already discussed about these tools in our previous posts. But, today we are going to discuss about Build management tool. This is one of the most important tool which required in any kind of software development. In this article we are going to discuss about Top Build Management Tools.
But before that let’s have a quick overview on Build management.
Build management is actually a process of collecting all the components in a software release, performing all the automated tasks to compile, build and test the system and then deploy onto the development and testing environments in preparation for staging. It has become an important part of software development in testing process.
But you can not simply do build management without tools. it is also important to ensure that tools are selected properly and thoroughly so that each of them provides the desired service.
So, without wasting any time let’s have a look on top 5 build management tools
1. Apache Maven
 Apache Maven
Maven is an open source build management tool which is distributed under Apache License. It is basically used for Java projects. let’s have a look on key feature of Maven tool
Key Features
  • Open source
  • Based on Project Object Model or POM
  • Release management and distribution publication
  • Coherent site of project information
  • Instant access to new features
  • Extensible with plugins
  • Works easily with multiple projects simultaneously
  • Simple project setup

2. Gradle

 

 Gradle

Gradle is also an open source build management tool which is distributed under Apache License. It is written in java and groovy supports cross platform. Let’s have a look on key features

Key Features
  • Open source
  • Designed for multiple projects
  • Supports incremental builds
  • Rich API
  • Mature ecosystem of plugins
  • Ease of migration
  • First build integration tool
  • Declarative builds and build-by-convention

3. Apache Ant

 

Apache Ant
Apache Ant is also an open source build automation tool which is distributed under Apache License. It is also a Java based build tool. Let’s have a look on key features
Key Features
  • open source
  • Ease of Use
  • Independent Platform
  • Can execute test scripts and test suites
  • Can copy files to at different locations
  • Supports Junit 3, Junit 4, Testing etc.
  • Able to compile java based applications
  • Can check out the code from version control system (SVN, GIT, CVS etc).
4. MSBuild
 MSBuild
MsBuild or Microsoft build tools as its name indicates it belongs to Microsoft which is written in C# and supports .Net framework and available under MIT license.
Key features
  • Able to build Visual Studio projects without Visual Studio IDE installed
  • Now bundled with Visual Studio
  • Multitargeting
  • Description language – XML
5. FinalBuilder
 FinalBuilder
Finalbuilder is a build tool which supports Windows platform and it is developed by VSoft Technologies in the year 2000. It is available under Proprietary license.
Key Features
  • It can present your build process in a structured manner
  • With FinalBuilder you don’t need to edit xml, or  write scripts
  • Allows builds to be scheduled to run daily, weekly or whenever you wish
  • Extensive library of pre-written actions to automate every common task in build process
  • Integrated Debugging
  • Detailed Logging
  • Version Control Integration
Do you agree with this list? If not than feel free to respond in the comment box with your own take on the top build management tools. One more thing, I would like to add here, if you need help to learn all these build tools or DevOps courses than scmGalaxy can help you in this. scmGalaxy is a community of DevOps professionals who are well experienced in this domain. So, feel free to reach us.
Tagged : / / / / / / / / / / / / /

Simple Ant Example – clean, prepare, and compile tasks

ant-clean-prepare-and-compile-tasks

Sample Ant clean, prepare, and compile tasks

<target name=”clean”>
<echo>=== CLEAN ===</echo>
<delete failonerror=”false”>
<fileset dir=”${dest.dir}” includes=”**/*”/>
</delete>
<delete dir=”${temp.dir}” />
</target>

<target name=”prepare” depends=”clean”>
<echo>=== PREPARE ===</echo>
<mkdir dir=”${dest.dir}” />
<mkdir dir=”${temp.dir}” />
<mkdir dir=”${temp.dir.lib}” />
<mkdir dir=”${temp.dir.meta-inf}” />
<mkdir dir=”${temp.dir.web-inf}” />
<mkdir dir=”${temp.dir.classes}” />
</target>

<target name=”compile” depends=”prepare”>
<echo>=== COMPILE ===</echo>
<echo>Compiling ${src.dir} files …</echo>
<javac debug=”on” srcdir=”${src.dir}” destdir=”${temp.dir.classes}” includes=”**/*”>
<classpath refid=”build.class.path” />
</javac>

<!– compile files on the src-tests path –>
<echo>Compiling ${src.tests.dir} files …</echo>
<javac debug=”on” srcdir=”${src.tests.dir}” destdir=”${temp.dir.classes}” includes=”com/**”>
<classpath refid=”build.class.path” />
</javac>
</target>

Tagged : / / / / / / / / / / / / / / / /

Flow Diagram and GUI tools for Apache Ant

apache-ant-flow-diagram-and-gui-tools

Nurflugel AntScript Visualizer

Link:
http://www.nurflugel.com/webstart/AntScriptVisualizer

About:
Ant Script Visualizer is a program I’ve written to make visualizing how your Ant targets and scripts are related to one another.

Ever take a look at an Ant build script and, although perfectly readable, not really “see” all the dependencies between targets?

What targets depend on a certain taskdef? Or a macrodef? Do macrodefs rely on other macrodefs? And all those imported Ant scripts – where do they fit in? This program was designed to show that, by importing your Ant scripts and creating graphic file representations of them. Say what?

OK, here’s an example of the output for the build file used for this program:

Features
# Parses build files for the following task usages:

* target
* ant
* antcall
* depends
* property
* import
* taskdef
* macrodef

# Groups results by build file subgraphs (default), or optionally, all items together in one graph
# Ability to filter/show included obects by target, imported files, ant calls, taskdefs, and macrodefs
# Output formats: PNG (default for PC), PDF (default for OS X, not available otherwise), SVG.

 

Grand

Links:
http://www.ggtools.net/grand/
About:
Grand is a tool to create visual representation of ant target dependencies. It differs from tools like Vizant or AntGraph  by a totally different approach, relying on the Ant API rather than parsing directly the XML files. This enables Grand to provide some nifty features such as the support of the ant 1.6.x tasks like import or subant.

 

Vizant

Links:
http://vizant.sourceforge.net/

About:
Vizant is an Apache Ant task to create Graphviz DOT source code from an Ant buildfile. The image created from the DOT source code shows the targets dependency.

Tagged : / / / / / / / / / / / / / / /

Apache Ant – A Complete TASK Reference

apache-ant-complete-task-reference

Apache Ant Task: zip

Description:

Creates a zipfile.

The basedir attribute is the reference directory from where to zip.

Note that file permissions will not be stored in the resulting zipfile.

It is possible to refine the set of files that are being zipped. This can be done with the includes, includesfile, excludes, excludesfile and defaultexcludes attributes. With the includes or includesfile attribute you specify the files you want to have included by using patterns. The exclude or excludesfile attribute is used to specify the files you want to have excluded. This is also done with patterns. And finally with the defaultexcludes attribute, you can specify whether you want to use default exclusions or not. See the section on directory based tasks, on how the inclusion/exclusion of files works, and how to write patterns.

This task forms an implicit FileSet and supports all attributes of (dir becomes basedir) as well as the nested , and elements.

Or, you may place within it nested file sets, or references to file sets. In this case basedir is optional; the implicit file set is only used if basedir is set. You may use any mixture of the implicit file set (with basedir set, and optional attributes like includes and optional subelements like ); explicit nested elements so long as at least one fileset total is specified. The ZIP file will only reflect the relative paths of files within each fileset. The Zip task and its derivatives know a special form of a fileset named zipfileset that has additional attributes (described below).

The Zip task also supports the merging of multiple zip files into the zip file. This is possible through either the src attribute of any nested filesets or by using the special nested fileset zipgroupfileset.

The update parameter controls what happens if the ZIP file already exists. When set to yes, the ZIP file is updated with the files specified. (New files are added; old files are replaced with the new versions.) When set to no (the default) the ZIP file is overwritten if any of the files that would be added to the archive are newer than the entries inside the archive. Please note that ZIP files store file modification times with a granularity of two seconds. If a file is less than two seconds newer than the entry in the archive, Ant will not consider it newer.

The whenempty parameter controls what happens when no files match. If skip (the default), the ZIP is not created and a warning is issued. If fail, the ZIP is not created and the build is halted with an error. If create, an empty ZIP file (explicitly zero entries) is created, which should be recognized as such by compliant ZIP manipulation tools.

This task will now use the platform’s default character encoding for filenames – this is consistent with the command line ZIP tools, but causes problems if you try to open them from within Java and your filenames contain non US-ASCII characters. Use the encoding attribute and set it to UTF8 to create zip files that can safely be read by Java.

Starting with Ant 1.5.2, can store Unix permissions inside the archive (see description of the filemode and dirmode attributes for ). Unfortunately there is no portable way to store these permissions. Ant uses the algorithm used by Info-Zip’s implementation of the zip and unzip commands – these are the default versions of zip and unzip for many Unix and Unix-like systems.

Please note that the zip format allows multiple files of the same fully-qualified name to exist within a single archive. This has been documented as causing various problems for unsuspecting users. If you wish to avoid this behavior you must set the duplicate attribute to a value other than its default, “add”.

Parameters:

Attribute Description Required
destfile the zip-file to create. Exactly one of the two.
zipfile the deprecated old name of destfile. No
basedir the directory from which to zip the files. No
compress Not only store data but also compress them, defaults to true. Unless you set the keepcompression attribute to false, this will apply to the entire archive, not only the files you’ve added while updating. No
keepcompression For entries coming from existing archives (like nested zipfilesets or while updating the archive), keep the compression as it has been originally instead of using the compress attribute. Defaults false. Since Ant 1.6 No
encoding The character encoding to use for filenames inside the zip file. For a list of possible values see http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html. Defaults to the platform’s default character encoding. No
filesonly Store only file entries, defaults to false No
includes comma- or space-separated list of patterns of files that must be included. All files are included when omitted. No
includesfile the name of a file. Each line of this file is taken to be an include pattern No
excludes comma- or space-separated list of patterns of files that must be excluded. No files (except default excludes) are excluded when omitted. No
excludesfile the name of a file. Each line of this file is taken to be an exclude pattern No
defaultexcludes indicates whether default excludes should be used or not (“yes”/”no”). Default excludes are used when omitted. No
update indicates whether to update or overwrite the destination file if it already exists. Default is “false”. No
whenempty behavior when no files match. Valid values are “fail”, “skip”, and “create”. Default is “skip” No
duplicate behavior when a duplicate file is found. Valid values are “add”, “preserve”, and “fail”. The default value is “add”. No
roundup Whether the file modification times will be rounded up to the next even number of seconds.
Zip archives store file modification times with a granularity of two seconds, so the times will either be rounded up or down. If you round down, the archive will always seem out-of-date when you rerun the task, so the default is to round up. Rounding up may lead to a different type of problems like JSPs inside a web archive that seem to be slightly more recent than precompiled pages, rendering precompilation useless.
Defaults to true. Since Ant 1.6.2
No
comment Comment to store in the archive. Since Ant 1.6.3 No
level Non-default level at which file compression should be performed. Valid values range from 0 (no compression/fastest) to 9 (maximum compression/slowest). Since Ant 1.7 No

 

Example:

Zips all files in the htdocs/manual directory into a file called manual.zip in the ${dist} directory. zips all files in the htdocs/manual directory into a file called manual.zip in the ${dist} directory. If manual.zip doesn’t exist, it is created; otherwise it is updated with the new/changed files.
Code:

basedir=”htdocs/manual”
/>

Code:

basedir=”htdocs/manual”
update=”true”
/>

 
Zips all files in the htdocs/manual directory. Files in the directory mydocs, or files with the name todo.html are excluded. Zips all files in the htdocs/manual directory. Only html files under the directory api are zipped, and files with the name todo.html are excluded.
Code:

basedir=”htdocs/manual”
excludes=”mydocs/**, **/todo.html”
/>

Code:

basedir=”htdocs/manual”
includes=”api/**/*.html”
excludes=”**/todo.html”
/>

Zips all files in the htdocs/manual directory, and also adds the file ChangeLog.txt in the current directory. ChangeLog.txt will be added to the top of the ZIP file, just as if it had been located at htdocs/manual/ChangeLog.txt. zips all files in the htdocs/manual directory into the docs/user-guide directory in the archive, adds the file ChangeLog27.txt in the current directory as docs/ChangeLog.txt, and includes all the html files in exampleszip under docs/examples. The archive might end up containing the files:
Code:

 

Code:: docs/user-guide/html/index.html
docs/ChangeLog.txt
docs/examples/index.html

 

zips all files in the htdocs/manual directory into the docs/user-guide directory in the archive and includes all the files in any file that maches examples*.zip, such as all files within examples1.zip or examples_for_brian.zip. Re-packages a TAR archive as a ZIP archive. If Unix file permissions have been stored as part of the TAR file, they will be retained in the resulting ZIP archive.
Code:

 

Code::

 

Debugging

 

Apache Ant Task: Concat

Description:

Concatenates one or more resources to a single file or to the console. The destination file will be created if it does not exist. Since Ant 1.7.1, this task can be used as a Resource Collection that will return exactly one resource.

Parameters:

Attribute Description Required
destfile The destination file for the concatenated stream. If not specified the console will be used instead. No
append Specifies whether or not the file specified by ‘destfile’ should be appended. Defaults to “no”. No
force Specifies whether or not the file specified by ‘destfile’ should be written to even if it is newer than all source files. since Ant 1.6. Defaults to “yes”. No
encoding Specifies the encoding for the input files. Please see http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html for a list of possible values. Defaults to the platform’s default character encoding. No
outputencoding The encoding to use when writing the output file since Ant 1.6. Defaults to the value of the encoding attribute if given or the default JVM encoding otherwise. No
fixlastline Specifies whether or not to check if each file concatenated is terminated by a new line. If this attribute is “yes” a new line will be appended to the stream if the file did not end in a new line. since Ant 1.6. Defaults to “no”. This attribute does not apply to embedded text. No
eol Specifies what the end of line character are for use by the fixlastline attribute. since Ant 1.6 Valid values for this property are:

  • cr: a single CR
  • lf: a single LF
  • crlf: the pair CRLF
  • mac: a single CR
  • unix: a single LF
  • dos: the pair CRLF

The default is platform dependent. For Unix platforms, the default is “lf”. For DOS based systems (including Windows), the default is “crlf”. For Mac OS, the default is “cr”.

No
binary

 

Example:

Concatenate a string to a file: Concatenate a series of files to the console:
Code:

Hello, World!

Code:

 

 
Concatenate a single file, appending if the destination file exists: Concatenate a series of files, update the destination file only if is older that all the source files:
Code:

 

Code:

force=”no”>

files=”introduction.xml,overview.xml”/>

includes=”sections/*.xml”
excludes=”introduction.xml,overview.xml”/>

Concatenate a series of files, expanding ant properties Filter the lines containing project from build.xml and output them to report.output, prepending with a header
Code:

 

Code::

 

Lines that contain project
==========================

 

Concatenate a number of binary files.
Code:

 

Code::

 

Debugging

 

Apache Ant Task: ReplaceRegExp

Description:

ReplaceRegExp is a directory based task for replacing the occurrence of a given regular expression with a substitution pattern in a selected file or set of files.The output file is only written if it differs from the existing file. This prevents spurious rebuilds based on unchanged files which have been regenerated by this task.

Parameters:

Attribute Description Required
file file for which the regular expression should be replaced. Yes if no nested is used
match The regular expression pattern to match in the file(s) Yes, if no nested is used
replace The substitution pattern to place in the file(s) in place of the regular expression. Yes, if no nested is used
flags The flags to use when matching the regular expression. For more information, consult the Perl5 syntax
g : Global replacement. Replace all occurrences found
i : Case Insensitive. Do not consider case in the match
m : Multiline. Treat the string as multiple lines of input, using “^” and “$” as the start or end of any line, respectively, rather than start or end of string.
s : Singleline. Treat the string as a single line of input, using “.” to match any character, including a newline, which normally, it would not match.
No
byline Process the file(s) one line at a time, executing the replacement on one line at a time (true/false). This is useful if you want to only replace the first occurrence of a regular expression on each line, which is not easy to do when processing the file as a whole. Defaults to false. No
encoding The encoding of the file. since Ant 1.6 No – defaults to default JVM encoding

 

Example:

Replaces occurrences of the property name “OldProperty” with “NewProperty” in a properties file, preserving the existing value, in the file ${src}/build.properties This task supports a nested Regexp element to specify the regular expression. You can use this element to refer to a previously defined regular expression datatype instance.
Code:

match=”OldProperty=(.*)”
replace=”NewProperty=\1″
byline=”true”/>

Code:

 

 
This task supports a nested Substitution element to specify the substitution pattern. You can use this element to refer to a previously defined substitution pattern datatype instance. Replaces occurrences of the property name “OldProperty” with “NewProperty” in a properties file, preserving the existing value, in all files ending in .properties in the current directory
Code:

 

Code:

 

 

 

Replaces all whitespaces (blanks, tabs, etc) by one blank remaining the line separator. So with input Check that both files one.txt and two.txt are present otherwise the build will fail.
Code:

 

 

replaces all whitespaces (blanks, tabs, etc) by one blank remaining the line separator. So with input

<>

T E S T

<>
<>

would converted to

 

T E S T

 

 

 

Code::

 

Debugging

Apache Ant Task: Checksum

Description:

Generates checksum for files. This task can also be used to perform checksum verifications.

Note that many popular message digest functions – including MD5 and SHA-1 – have been broken recently. If you are going to use the task to create checksums used in an environment where security is important, please take some time to investigate the algorithms offered by your JCE provider. Note also that some JCE providers like the one by The Legion of the Bouncy Castle, the GNU project or the Technical University Graz offer more digest algorithms than those built-in into your JDK.

Warning: the case of the extension is that of the algorithm used. If you ask for “SHA1”, you get a .SHA1 extension; if you ask for “sha1”, you get a file ending in .sha1. The Java Crypto Engines are case-insensitive in matching algorithms, so choose a name to match your desired output extension, or set the fileext attribute.

Parameters:

Attribute Description Required
file The file to generate checksum for. One of either file or at least one nested (filesystem-only) resource collection.
todir The root directory where checksums should be written. No. If not specified, checksum files will be written to the same directory as the files themselves. since Ant 1.6
algorithm Specifies the algorithm to be used to compute the checksum. Defaults to “MD5”. Other popular algorithms like “SHA” may be used as well. No
provider Specifies the provider of the algorithm. No
fileext The generated checksum file’s name will be the original filename with the fileext added to it. Defaults to a “.” and the algorithm name being used. No
property This attribute can mean two different things, it depends on the presence of the verifyproperty attribute.
If you don’t set the verifyproperty attribute, property specifies the name of the property to be set with the generated checksum value.
If you set the verifyproperty attribute, property specifies the checksum you expect to be generated (the checksum itself, not a name of a property containing the checksum).
This cannot be specified when fileext is being used or when the number of files for which checksums is to be generated is greater than 1.
No
pattern Specifies the pattern to use as a pattern suitable for MessageFormat where {0} is replaced with the checksum and {1} with the file name. No – default is “{0}”.
format Specifies the pattern to use as one of a well-known format. Supported values are

name pattern description
CHECKSUM {0} only the checksum itself
MD5SUM {0} *{1} the format of GNU textutils md5sum
SVF MD5 ({1}) = {0} the format of BSDs md5 command
No – default is “CHECKSUM”.
totalproperty If specified, this attribute specifies the name of the property that will hold a checksum of all the checksums and file paths. The individual checksums and the relative paths to the files within the resource collections in which they are defined will be used to compute this checksum. (The file separators in the paths will be converted to ‘/’ before computation to ensure platform portability). since Ant 1.6 No
forceoverwrite Overwrite existing files even if the destination files are newer. Defaults to “no”. No
verifyproperty Specifies the name of the property to be set with “true” or “false” depending upon whether the generated checksum matches the existing checksum. When this is set, the generated checksum is not written to a file or property, but rather, the content of the file or property is used to check against the generated checksum. No
readbuffersize The size of the buffer (in bytes) to use when reading a file. Defaults to “8192” – you may get a better performance on big files if you increase this value. No

 

Example:

Generates a MD5 checksum for foo.bar and stores the checksum in the destination file foo.bar.MD5. foo.bar.MD5 is overwritten only if foo.bar is newer than itself. Generates a MD5 checksum for foo.bar and stores the checksum in foo.bar.MD5. If foo.bar.MD5 already exists, it is overwritten.
Code:

 

Code:

 

 
Generates a MD5 checksum for foo.bar and stores it in the Project Property foobarMD5. Generates a MD5 checksum for foo.bar, compares it against foo.bar.MD5 and sets isMD5ok to either true or false, depending upon the result
Code:

 

Code:

 

Generates a SHA checksum for foo.bar and stores the checksum in the destination file foo.bar.asc. foo.bar.asc is overwritten only if foo.bar is newer than itself. Generates a MD5 checksum for foo.bar, compares it against the value of the property md5, and sets isEqual to either true or false, depending upon the result.
Code:

 

Code::

 

Works just like Example 1, but generates a .MD5 file for every file that begins with the name foo. Works like Example 4, but only sets isChecksumEqual to true, if the checksum matches – it will never be set to false. This example demonstrates use with the Condition task.
Code:

 

Code::

 

Debugging

Apache Ant Task: Fail

Description:

Exits the current build (just throwing a BuildException), optionally printing additional information.The message of the Exception can be set via the message attribute or character data nested into the element.

Parameters:

Attribute Description Required
message A message giving further information on why the build exited No
if Only fail if a property of the given name exists in the current project No
unless Only fail if a property of the given name doesn’t exist in the current project No
status Exit using the specified status code; assuming the generated Exception is not caught, the JVM will exit with this status. Since Ant 1.6.2 No

 

Example:

Exit the current build with no further information given. Exit the current build and print something like the following to wherever your output goes:
Code:

 

Code:

 

BUILD FAILED
build.xml:4: No message
BUILD FAILED
build.xml:4: Something wrong here.
Exit the current build and print something like the following to wherever your output goes: Exit the current build and print something like the following to wherever your output goes:
Code:

Something wrong here.

Code:

 

BUILD FAILED
build.xml:4: Something wrong here.
BUILD FAILED
build.xml:2: unless=thisdoesnotexist
Using a condition to achieve the same effect Check that both files one.txt and two.txt are present otherwise the build will fail.
Code:

 

Code::

 

BUILD FAILED
build.xml:2: condition satisfied
Output:

Debugging

 

Tagged : / / / / / / / / / / / / / / /

Usage of ANT_OPTS in Ant Script | ANT_OPTS capabilities

ant_opts-in-ant-script

Usage of ANT_OPTS in Ant Script | ANT_OPTS capabilities

Ant has three environment variables that you can use to set its default behavior.
• ANT_ARGS Set this variable to include those options you use frequently.
• ANT_OPTS is a list of arguments that you want to pass to the JVM that will run Ant.
• JAVACMD is the absolute path to the Java executable you want Ant to use. you may specify a value for the JAVACMD environment variable. This defaults to %JAVA_HOME%\bin\java, typically invoking the JVM provided in Sun’s Java Development Kit. Ant provides JAVACMD for those who wish to specify an alternate JVM. full path of the Java executable. Use this to invoke a different JVM than JAVA_HOME/bin/java(.exe).

These are useful environment variables that the Ant wrapper scripts use when
invoking Ant: ANT_OPTS and ANT_ARGS. Neither of these is typically set by users,
but each can provide value for certain situations.

The ANT_OPTS environment variable provides options to the JVM executing Ant,
such as system properties and memory configuration. ANT_OPTS – command-line arguments that should be passed to the JVM. For example, you can define system properties or set the maximum Java heap size here.

For authenticated proxy:
Set your ANT_OPTS environment variable to configure your proxy if you have one. For instance:
set ANT_OPTS=-Dhttp.proxyHost=myproxy -Dhttp.proxyPort=3128

You can set these properties by either modifying Ant’s startup script, or by
using the ANT_OPTS environment variable. The following example shows the Windows commands to specify these properties using ANT_OPTS, and then to invoke Ant:
set ANT_OPTS=-DproxySet=true -DproxyHost=localhost -DproxyPort=80
ant mytarget
The same trick works on Unix, although the syntax is slightly different depending on which
shell you use:
$ export ANT_OPTS=”-DproxySet=true -DproxyHost=localhost -DproxyPort=80″
$ ant mytarget

set ANT_OPTS=-Dhttp.proxyHost=myproxyhost -Dhttp.proxyPort=8080 -Dhttp.proxyUserName=myproxyusername -Dhttp.proxyPassword=myproxypassword -Dhttps.proxyHost=myproxyhost -Dhttps.proxyPort=8080

 

Use ANT_OPTS to control Ant’s virtual machine settings.
Some tasks may require more memory, which you can set in the ANT_OPTS environment variable, using the appropriate mechanism for your platform:
set ANT_OPTS=-Xmx500M
export ANT_OPTS=-Xmx500M

Setting the maximum heap size is another common use of ANT_OPTS. Here is how we set the maximum size to 128 MB when using Sun’s JDK:
set ANT_OPTS=-Xmx128m

One environment variable you may wish to set is ANT_OPTS. The value of this variable is passed as a JVM argument. Specifying system properties is a common use. In this simple
example, we pass the log.dir system property to the JVM running Ant:
$ set ANT_OPTS=-Dlog.dir=C:\logs
$ ant run
Now this property is available within the buildfile, for instance:
<echo>Log directory is set to: ${log.dir}</echo>
If the buildfile runs a Java application, the property may be retrieved from within it as
follows:
String logDir = System.getProperty(“log.dir”);

 

Troubleshoot: Illegal Java options in the ANT_OPTS variable
The environment variable ANT_OPTS provides a means to pass options into Ant,
such as a permanent definition of some properties, or the memory parameters for
Java. The variable must contain only options the local JVM recognizes. Any invalid
parameter will generate an error message such as the following (where ANT_OPTS was
set to –3):
Unrecognized option: -3
Could not create the Java virtual machine.

If the variable contains a string that is mistaken for the name of the Java class to run
as the main class, then a different error appears:

Exception in thread “main” java.lang.NoClassDefFoundError: error-string
Test: Examine ANT_OPTS and verify that the variable is unset or contains valid
JVM options.
Fix: Correct or clear the variable.

Tagged : / / / / / / / / / / / / / / /

Power Point PPT: Apache Ant – Complete Guide

apache-ant-ppt

Power Point PPT: Apache Ant

 

Tagged : / / / / / / / / / / / /