ANT启动脚本详细说明

来源:互联网 发布:网络电视浏览器在哪里 编辑:程序博客网 时间:2024/04/30 22:05

广告靠左。文字在右

<script type="text/javascript"><!--google_ad_client = "pub-1926348199765453";/* 文章底部 */google_ad_slot = "3855136352";google_ad_width = 336;google_ad_height = 280;// --></script><script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>

    <target name="sh" depends="compile">
     <exec command="sh ./runsvr.sh" failonerror="false"/>
    </target>

附录:
<javac>任务介绍:
Javac
Description
Compiles a Java source tree.
Thesource and destination directory will be recursively scanned for Javasource files to compile. Only Java files that have no corresponding .class file or where the class file is older than the .java file will be compiled.
Note:Ant uses only the names of the source and class files to find theclasses that need a rebuild. It will not scan the source and thereforewill have no knowledge about nested classes, classes that are nameddifferent from the source file, and so on. See the <depend> task for dependency checking based on other than just existence/modification times.
When the source files are part of a package, the directory structure of the source tree should follow the package hierarchy.
It is possible to refine the set of files that are being compiled. This can be done with the includes, includesfile, excludes, and excludesfile attributes. With the includes or includesfile attribute, you specify the files you want to have included. The exclude or excludesfileattribute is used to specify the files you want to have excluded. Inboth cases, the list of files can be specified by either the filename,relative to the directory(s) specified in the srcdir attribute or nested <src> element(s), or by using wildcard patterns. See the section on directory-based tasks, for information on how the inclusion/exclusion of files works, and how to write wildcard patterns.
It is possible to use different compilers. This can be specified by either setting the global build.compiler property, which will affect all <javac> tasks throughout the build, or by setting the compiler attribute, specific to the current <javac> task. Valid values for either the build.compiler property or the compiler attribute are:
  • classic (the standard compiler of JDK 1.1/1.2) – javac1.1 and javac1.2 can be used as aliases.
  • modern (the standard compiler of JDK 1.3/1.4/1.5) – javac1.3 and javac1.4 and javac1.5 can be used as aliases.
  • jikes (the Jikes compiler).
  • jvc (the Command-Line Compiler from Microsoft's SDK for Java / Visual J++) – microsoft can be used as an alias.
  • kjc (the kopi compiler).
  • gcj (the gcj compiler from gcc).
  • sj (Symantec java compiler) – symantec can be used as an alias.
  • extJavac (run either modern or classic in a JVM of its own).
The default is javac1.x with xdepending on the JDK version you use while you are running Ant. If youwish to use a different compiler interface than those supplied, you canwrite a class that implements the CompilerAdapter interface (package org.apache.tools.ant.taskdefs.compilers). Supply the full classname in the build.compiler property or the compiler attribute.
The fork attribute overrides the build.compiler property or compiler attribute setting and expects a JDK1.1 or higher to be set in JAVA_HOME.
You can also use the compiler attribute to tell Ant which JDK version it shall assume when it puts together the command line switches - even if you set fork="true". This is useful if you want to run the compiler of JDK 1.1 while you current JDK is 1.2+. If you use compiler="javac1.1" and (for example) depend="true" Ant will use the command line switch -depend instead of -Xdepend.
This task will drop all entries that point to non-existent files/directories from the classpath it passes to the compiler.
Windows Note:When the modern compiler is used in unforked mode on Windows, it locks up the files present in the classpath of the <javac>task, and does not release them. The side effect of this is that youwill not be able to delete or move those files later on in the build.The workaround is to fork when invoking the compiler.
Parameters
Attribute
Description
Required
srcdir
Location of the java files. (See the note below.)
Yes, unless nested <src> elements are present.
destdir
Location to store the class files.
No
includes
Comma- or space-separated list of files (may be specified using wildcard patterns) that must be included; all .java files are included when omitted.
No
includesfile
The name of a file that contains a list of files to include (may be specified using wildcard patterns).
No
excludes
Comma-or space-separated list of files (may be specified using wildcardpatterns) that must be excluded; no files (except default excludes) areexcluded when omitted.
No
excludesfile
The name of a file that contains a list of files to exclude (may be specified using wildcard patterns).
No
classpath
The classpath to use.
No
sourcepath
The sourcepath to use; defaults to the value of the srcdir attribute (or nested <src> elements). To suppress the sourcepath switch, use sourcepath="".
No
bootclasspath
Location of bootstrap class files.
No
classpathref
The classpath to use, given as a reference to a path defined elsewhere.
No
sourcepathref
The sourcepath to use, given as a reference to a path defined elsewhere.
No
bootclasspathref
Location of bootstrap class files, given as a reference to a path defined elsewhere.
No
extdirs
Location of installed extensions.
No
encoding
Encoding of source files. (Note: gcj doesn't support this option yet.)
No
nowarn
Indicates whether the -nowarn switch should be passed to the compiler; defaults to off.
No
debug
Indicates whether source should be compiled with debug information; defaults to off. If set to off, -g:nonewill be passed on the command line for compilers that support it (forother compilers, no command line argument will be used). If set to true, the value of the debuglevel attribute determines the command line argument.
No
debuglevel
Keyword list to be appended to the -g command-line switch. This will be ignored by all implementations except modern, classic(ver >= 1.2) and jikes. Legal values are none or a comma-separated list of the following keywords: lines, vars, and source. If debuglevel is not specified, by default, nothing will be appended to -g. If debug is not turned on, this attribute will be ignored.
No
optimize
Indicates whether source should be compiled with optimization; defaults to off.
No
deprecation
Indicates whether source should be compiled with deprecation information; defaults to off.
No
target
Generate class files for specific VM version (e.g., 1.1 or 1.2). Notethat the default value depends on the JVM that is running Ant. Inparticular, if you use JDK 1.4+ the generated classes will not beusable for a 1.1 Java VM unless you explicitly set this attribute tothe value 1.1 (which is the default value for JDK 1.1 to 1.3). Wehighly recommend to always specify this attribute.
No
verbose
Asks the compiler for verbose output; defaults to no.
No
depend
Enables dependency-tracking for compilers that support this (jikes and classic).
No
includeAntRuntime
Whether to include the Ant run-time libraries in the classpath; defaults to yes.
No
includeJavaRuntime
Whether to include the default run-time libraries from the executing VM in the classpath; defaults to no.
No
fork
Whether to execute javac using the JDK compiler externally; defaults to no.
No
executable
Complete path to the javac executable to use in case of fork="yes". Defaults to the compiler of the Java version that is currently running Ant. Ignored if fork="no".
Since Ant 1.6 this attribute can also be used to specify the path to the executable when using jikes, jvc, gcj or sj.
No
memoryInitialSize
The initial size of the memory for the underlying VM, if javac is run externally; ignored otherwise. Defaults to the standard VM memory setting. (Examples: 83886080, 81920k, or 80m)
No
memoryMaximumSize
The maximum size of the memory for the underlying VM, if javac is run externally; ignored otherwise. Defaults to the standard VM memory setting. (Examples: 83886080, 81920k, or 80m)
No
failonerror
Indicates whether the build will continue even if there are compilation errors; defaults to true.
No
source
Value of the -source command-line switch; will be ignored by all implementations prior to javac1.4 (or modern when Ant is not running in a 1.3 VM) and jikes.
If you use this attribute together with jikes, you must make sure that your version of jikes supports the -source switch. By default, no -source argument will be used at all.
Note that the default value depends on the JVM that is running Ant. We highly recommend to always specify this attribute.
No
compiler
The compiler implementation to use. If this attribute is not set, the value of the build.compiler property, if set, will be used. Otherwise, the default compiler for the current VM will be used. (See the above list of valid compilers.)
No
listfiles
Indicates whether the source files to be compiled will be listed; defaults to no.
No
tempdir
Where Ant should place temporary files. This is only used if the task is forked and the command line args length exceeds 4k. Since Ant 1.6.
No; default is java.io.tmpdir.
Parameters specified as nested elements
This task forms an implicit FileSet and supports all attributes of <fileset> (dir becomes srcdir) as well as the nested <include>, <exclude> and <patternset> elements.
src, classpath, sourcepath, bootclasspath and extdirs
<javac>'s srcdir, classpath, sourcepath, bootclasspath, and extdirs attributes are path-like structures and can also be set via nested <src>, <classpath>, <sourcepath>, <bootclasspath> and <extdirs> elements, respectively.
compilerarg
You can specify additional command line arguments for the compiler with nested <compilerarg> elements. These elements are specified like Command-line Arguments but have an additional attribute that can be used to enable arguments only if a given compiler implementation will be used.
Attribute
Description
Required
value
See Command-line Arguments.
Exactly one of these.
line
file
path
compiler
Onlypass the specified argument if the chosen compiler implementationmatches the value of this attribute. Legal values are the same as thosein the above list of valid compilers.)
No
Examples
 <javac srcdir="${src}"
         destdir="${build}"
         classpath="xyz.jar"
         debug="on"
         source="1.4"
 />
compiles all .java files under the ${src} directory, and stores the .class files in the ${build} directory. The classpath used includes xyz.jar, and compiling with debug information is on. The source level is 1.4, so you can use assert statements.
 <javac srcdir="${src}"
         destdir="${build}"
         fork="true"
         source="1.2"
         target="1.2"
 />
compiles all .java files under the ${src} directory, and stores the .class files in the ${build} directory. This will fork off the javac compiler using the default javac executable. The source level is 1.2 (similar to 1.1 or 1.3) and the class files should be runnable under JDK 1.2+ as well.
 <javac srcdir="${src}"
         destdir="${build}"
         fork="java$javac.exe"
         source="1.5"
 />
compiles all .java files under the ${src} directory, and stores the .class files in the ${build} directory. This will fork off the javac compiler, using the executable named java$javac.exe. Note that the $ sign needs to be escaped by a second one. The source level is 1.5, so you can use generics.
 <javac srcdir="${src}"
         destdir="${build}"
         includes="mypackage/p1/**,mypackage/p2/**"
         excludes="mypackage/p1/testpackage/**"
         classpath="xyz.jar"
         debug="on"
 />
compiles .java files under the ${src} directory, and stores the .class files in the ${build} directory. The classpath used includes xyz.jar, and debug information is on. Only files under mypackage/p1 and mypackage/p2 are used. All files in and below the mypackage/p1/testpackagedirectory are excluded from compilation. You didn't specify a source ortarget level, so the actual values used will depend on which JDK youran Ant with.
 <javac srcdir="${src}:${src2}"
         destdir="${build}"
         includes="mypackage/p1/**,mypackage/p2/**"
         excludes="mypackage/p1/testpackage/**"
         classpath="xyz.jar"
         debug="on"
 />
is the same as the previous example, with the addition of a second source path, defined by the property src2. This can also be represented using nested <src> elements as follows:
 <javac destdir="${build}"
         classpath="xyz.jar"
         debug="on">
    <src path="${src}"/>
    <src path="${src2}"/>
    <include name="mypackage/p1/**"/>
    <include name="mypackage/p2/**"/>
    <exclude name="mypackage/p1/testpackage/**"/>
 </javac>
Ifyou want to run the javac compiler of a different JDK, you should tellAnt, where to find the compiler and which version of JDK you will beusing so it can choose the correct command line switches. The followingexample executes a JDK 1.1 javac in a new process and uses the correctcommand line switches even when Ant is running in a Java VM of adifferent version:
 <javac srcdir="${src}"
        destdir="${build}"
         fork="yes"
         executable="/opt/java/jdk1.1/bin/javac"
         compiler="javac1.1"
 />
Note: If you wish to compile only source files located in certain packages below a common root, use the include/exclude attributes or <include>/<exclude> nested elements to filter for these packages. Do not include part of your package structure in the srcdir attribute (or nested <src> elements), or Ant will recompile your source files every time you run your compile target. See the Ant FAQ for additional information.
Ifyou wish to compile only files explicitly specified and disable javac'sdefault searching mechanism then you can unset the sourcepathattribute:
 <javac sourcepath="" srcdir="${src}"
         destdir="${build}" >
    <include name="**/*.java"/>
    <exclude name="**/Example.java"/>
 </javac>
Thatway the javac will compile all java source files under "${src}"directory but skip the examples. The compiler will even produce errorsif some of the non-example files refers to them.
Note:If you are using Ant on Windows and a new DOS window pops up for everyuse of an external compiler, this may be a problem of the JDK you areusing. This problem may occur with all JDKs < 1.2.
Jikes Notes
You need Jikes 1.15 or later.
Jikessupports some extra options, which can be set be defining theproperties shown below prior to invoking the task. The setting for eachproperty will be in affect for all <javac>tasks throughout the build. The Ant developers are aware that this isugly and inflexible – expect a better solution in the future. All theoptions are boolean, and must be set to true or yes to be interpreted as anything other than false. By default, build.compiler.warnings is true, while all others are false.
Property
Description
Default
build.compiler.emacs
Enable emacs-compatible error messages.
false
build.compiler.fulldepend
Enable full dependency checking; see
the +F switch in the Jikes manual.
false
build.compiler.pedantic
Enable pedantic warnings.
false
build.compiler.warnings
Deprecated. Use <javac>'s nowarn attribute instead.
Don't disable warning messages.
true
Jvc Notes
Jvc will enable Microsoft extensions unless you set the property build.compiler.jvc.extensions to false before invoking <javac>.
 
 
<java>任务介绍:
Java
Description
Executes a Java class within the running (Ant) VM or forks another VM if specified.
If odd things go wrong when you run this task, set fork="true" to use a new JVM.
As of Ant 1.6.3, you can interact with a forked VM, as well as sending input to it via the input and inputstring attributes.
Parameters
Attribute
Description
Required
classname
the Java class to execute.
Either jar or classname
jar
thelocation of the jar file to execute (must have a Main-Class entry inthe manifest). Fork must be set to true if this option is selected.
Either jar or classname
args
the arguments for the class that is executed. deprecated, use nested <arg> elements instead.
No
classpath
the classpath to use.
No
classpathref
the classpath to use, given as reference to a PATH defined elsewhere.
No
fork
if enabled triggers the class execution in another VM (disabled by default)
No
spawn
if enabled allows to start a process which will outlive ant.
Requires fork=true, and not compatible with timeout, input, output, error, result attributes.
(disabled by default)
No
jvm
thecommand used to invoke the Java Virtual Machine, default is 'java'. Thecommand is resolved by java.lang.Runtime.exec(). Ignored if fork isdisabled.
No
jvmargs
the arguments to pass to the forked VM (ignored if fork is disabled). deprecated, use nested <jvmarg> elements instead.
No
maxmemory
Max amount of memory to allocate to the forked VM (ignored if fork is disabled)
No
failonerror
Stop the buildprocess if the command exits with a returncode other than 0. Default is "false" (see note)
No
resultproperty
Thename of a property in which the return code of the command should bestored. Only of interest if failonerror=false and if fork=true.
No
dir
The directory to invoke the VM in. (ignored if fork is disabled)
No
output
Nameof a file to which to write the output. If the error stream is not alsoredirected to a file or property, it will appear in this output.
No
error
The file to which the standard error of the command should be redirected.
No
logError
Thisattribute is used when you wish to see error output in Ant's log andyou are redirecting output to a file/property. The error output willnot be included in the output file/property. If you redirect error withthe "error" or "errorProperty" attributes, this will have no effect.
No
append
Whether output and error files should be appended to or overwritten. Defaults to false.
No
outputproperty
Thename of a property in which the output of the command should be stored.Unless the error stream is redirected to a separate file or stream,this property will include the error output.
No
errorproperty
The name of a property in which the standard error of the command should be stored.
No
input
Afile from which the executed command's standard input is taken. Thisattribute is mutually exclusive with the inputstring attribute
No; default is to take standard input from console (unless spawn="true")
inputstring
Astring which serves as the input stream for the executed command. Thisattribute is mutually exclusive with the input attribute.
No; default is to take standard input from console (unless spawn="true")
newenvironment
Do not propagate old environment when new environment variables are specified. Default is "false" (ignored if fork is disabled).
No
timeout
Stop the command if it doesn't finish within the specified time (given in milliseconds). It is highly recommended to use this feature only if fork is enabled.
No
Parameters specified as nested elements
arg and jvmarg
Use nested <arg> and <jvmarg> elements to specify arguments for the Java class and the forked VM respectively. See Command line arguments.
sysproperty
Use nested <sysproperty>elements to specify system properties required by the class. Theseproperties will be made available to the VM during the execution of theclass (either ANT's VM or the forked VM). The attributes for thiselement are the same as for environment variables.
syspropertyset
You can specify a set of properties to be used as system properties with syspropertysets.
since Ant 1.6.
classpath
Java's classpath attribute is a PATH like structure and can also be set via a nested classpath element.
bootclasspath
The location of bootstrap class files can be specified using this PATH like structure - will be ignored if fork is not true or the target VM doesn't support it (i.e. Java 1.1).
since Ant 1.6.
env
It is possible to specify environment variables to pass to the forked VM via nested env elements. See the description in the section about exec
Settings will be ignored if fork is disabled.
permissions
Security permissions can be revoked and granted during the execution of the class via a nested permissions element. For more information please see permissions
Whenthe permission RuntimePermission exitVM has not been granted (or hasbeen revoked) the System.exit() call will be intercepted and treatedlike indicated in failonerror.
Note: if you specify failonerror="true"and you do not specify permissions, a set of default permissions willbe added to your Java invocation to make sure that a non-zero returncode will lead to a BuildException.
Settings will be ignored if fork is enabled.
since Ant 1.6.
assertions
You can control enablement of Java 1.4 assertions with an <assertions> subelement.
Assertion statements are currently ignored in non-forked mode.
since Ant 1.6.
redirector
Since Ant 1.6.2
A nested I/O Redirectorcan be specified. In general, the attributes of the redirector behaveas the corresponding attributes available at the task level. The mostnotable peculiarity stems from the retention of the <java>attributes for backwards compatibility. Any file mapping is done usinga null sourcefile; therefore not all Mappertypes will return results. When no results are returned, redirectionspecifications will fall back to the task level attributes. In practicethis means that defaults can be specified for input, output, and erroroutput files.
Errors and return codes
By default the return code of a <java> is ignored. Alternatively, you can set resultproperty to the name of a property and have it assigned to the result code (barring immutability, of course). When you set failonerror="true", the only possible value for resultproperty is 0. Any non zero response is treated as an error and would mean the build exits.
Similarly, if failonerror="false" and fork="false" , then <java>must return 0 otherwise the build will exit, as the class was run by the build jvm.
Examples
       <java classname="test.Main">
         <arg value="-h"/>
         <classpath>
           <pathelement location="dist/test.jar"/>
           <pathelement path="${java.class.path}"/>
         </classpath>
       </java>
Run a class in this JVM with a new jar on the classpath
       <java jar="dist/test.jar"
           fork="true"
           failonerror="true"
           maxmemory="128m"
           >
         <arg value="-h"/>
         <classpath>
           <pathelement location="dist/test.jar"/>
           <pathelement path="${java.class.path}"/>
         </classpath>
       </java>
Runthe jar using the manifest supplied entry point, forking (as required),and with a maximum memory of 128MB. Any non zero return code breaks thebuild.
 <java classname="test.Main"/>
 <java classname="test.Main"
        fork="yes" >
    <sysproperty key="DEBUG" value="true"/>
    <arg value="-h"/>
    <jvmarg value="-Xrunhprof:cpu=samples,file=log.txt,depth=3"/>
 </java>
Note:you can not specify the (highly deprecated) MSJVM, "jview.exe" as theJVM, as it takes different parameters for other JVMs, That JVM can bestarted from <exec> if required.
 
Exec
Description
Executes a system command. When the os attribute is specified, then the command is only executed when Ant is run on one of the specified operating systems.
Notethat you cannot interact with the forked program, the only way to sendinput to it is via the input and inputstring attributes. Also note thatin Ant 1.6, any attempt to read input in the forked program willreceive an EOF (-1). This is a change from Ant 1.5, where such anattempt would block.
Windows Users
The <exec> task delegates to Runtime.exec which in turn apparently calls ::CreateProcess.It is the latter Win32 function that defines the exact semantics of thecall. In particular, if you do not put a file extension on theexecutable, only ".EXE" files are looked for, not ".COM", ".CMD" orother file types listed in the environment variable PATHEXT. That isonly used by the shell.
Cygwin Users
In general the <exec>task will not understand paths such as /bin/sh for the executableparameter. This is because the Java VM in which Ant is running is aWindows executable and is not aware of Cygwin conventions.
OpenVMS Users
The command specified using executable and <arg> elements is executed exactly as specified inside a temporary DCL script. This has some implications:
  • paths have to be written in VMS style
  • if your executable points to a DCL script remember to prefix it with an @-sign (e.g. executable="@[FOO]BAR.COM"), just as you would in a DCL script
For <exec> to work in an environment with a Java VM older than version 1.4.1-2 it is also required that the logical JAVA$FORK_SUPPORT_CHDIR is set to TRUE in the job table (see the JDK Release Notes).
Pleasenote that the Java VM provided by HP doesn't follow OpenVMS'conventions of exit codes. If you run a Java VM with this task, thetask may falsely claim that an error occured (or silently ignore anerror). Don't use this task to run JAVA.EXE, use a <java> task with the fork attribute set to true instead as this task will follow the VM's interpretation of exit codes.
RedHat S/390 Users
It has been reported on the VMESA-LISTSERVthat shell scripts invoked via the Ant Exec task must have theirinterpreter specified, i.e., the scripts must start with somethinglike:
#!/bin/bash
or the task will fail as follows:
[exec] Warning: UNIXProcess.forkAndExec native error: Exec format error
[exec] Result: 255
Parameters
Attribute
Description
Required
command
the command to execute with all command line arguments. deprecated, use executable and nested <arg> elements instead.
Exactly one of the two.
executable
the command to execute without any command line arguments.
dir
the directory in which the command should be executed.
No
os
listof Operating Systems on which the command may be executed. If thecurrent OS's name is contained in this list, the command will beexecuted. The OS's name is determined by the Java Virtual machine andis set in the "os.name" system property.
No
spawn
whether or not you want the command to be spawned
Default is false.
If you spawn a command, its output will not be logged by ant.
The input, output, error, and result property settings are not active when spawning a process.
since Ant 1.6
No
output
Nameof a file to which to write the output. If the error stream is not alsoredirected to a file or property, it will appear in this output.
No
error
The file to which the standard error of the command should be redirected. since Ant 1.6
No
logError
Thisattribute is used when you wish to see error output in Ant's log andyou are redirecting output to a file/property. The error output willnot be included in the output file/property. If you redirect error withthe "error" or "errorProperty" attributes, this will have no effect. since Ant 1.6
No
append
Whether output and error files should be appended to or overwritten. Defaults to false.
No
outputproperty
Thename of a property in which the output of the command should be stored.Unless the error stream is redirected to a separate file or stream,this property will include the error output.
No
errorproperty
The name of a property in which the standard error of the command should be stored. since Ant 1.6
No
input
Afile from which the executed command's standard input is taken. Thisattribute is mutually exclusive with the inputstring attribute. since Ant 1.6
No
inputstring
Astring which serves as the input stream for the executed command. Thisattribute is mutually exclusive with the input attribute. since Ant 1.6
No
resultproperty
the name of a property in which the return code of the command should be stored. Only of interest if failonerror=false.
No
timeout
Stop the command if it doesn't finish within the specified time (given in milliseconds).
No
failonerror
Stop the buildprocess if the command exits with a return code signaling failure. Defaults to false.
No
failifexecutionfails
Stop the build if we can't start the program. Defaults to true.
No
newenvironment
Do not propagate old environment when new environment variables are specified.
No, default is false
vmlauncher
Runcommand using the Java VM's execution facilities where available. Ifset to false the underlying OS's shell, either directly or through theantRun scripts, will be used. Under some operating systems, this givesaccess to facilities not normally available through the VM including,under Windows, being able to execute scripts, rather than theirassociated interpreter. If you want to specify the name of theexecutable as a relative path to the directory given by the dirattribute, it may become necessary to set vmlauncher to false as well.
No, default is true
resolveexecutable
Whenthis attribute is true, the name of the executable is resolved firstlyagainst the project basedir and if that does not exist, against theexecution directory if specified. On Unix systems, if you only want toallow execution of commands in the user's path, set this to false. since Ant 1.6
No, default is false
searchpath
Whenthis attribute is true nested, then system path environment variableswill be searched when resolving the location of the executable. since Ant 1.6.3
No, default is false
Examples
<exec dir="${src}" executable="cmd.exe" os="Windows 2000" output="dir.txt">
 <arg line="/c dir"/>
</exec>
Parameters specified as nested elements
arg
Command line arguments should be specified as nested <arg> elements. See Command line arguments.
env
It is possible to specify environment variables to pass to the system command via nested <env> elements.
Attribute
Description
Required
key
The name of the environment variable.
Yes
value
The literal value for the environment variable.
Exactly one of these.
path
Thevalue for a PATH like environment variable. You can use ; or : as pathseparators and Ant will convert it to the platform's local conventions.
file
The value for the environment variable. Will be replaced by the absolute filename of the file by Ant.
redirector
Since Ant 1.6.2
A nested I/O Redirectorcan be specified. In general, the attributes of the redirector behaveas the corresponding attributes available at the task level. The mostnotable peculiarity stems from the retention of the <exec>attributes for backwards compatibility. Any file mapping is done usinga null sourcefile; therefore not all Mappertypes will return results. When no results are returned, redirectionspecifications will fall back to the task level attributes. In practicethis means that defaults can be specified for input, output, and erroroutput files.
Errors and return codes
By default the return code of a <exec> is ignored; when you set failonerror="true" then any return code signaling failure (OS specific) causes the build to fail. Alternatively, you can set resultproperty to the name of a property and have it assigned to the result code (barring immutability, of course).
If the attempt to start the program fails with an OS dependent error code, then <exec> halts the build unless failifexecutionfails is set to false. You can use that to run a program if it exists, but otherwise do nothing.
Whatdo those error codes mean? Well, they are OS dependent. On Windowsboxes you have to look in include/error.h in your windows compiler orwine files; error code 2 means 'no such program', which usually meansit is not on the path. Any time you see such an error from any anttask, it is usually not an ant bug, but some configuration problem onyour machine.
Examples
<exec executable="emacs">
 <env key="DISPLAY" value=":1.0"/>
</exec>
starts emacs on display 1 of the X Window System.
<property environment="env"/>
<exec ... >
 <env key="PATH" path="${env.PATH}:${basedir}/bin"/>
</exec>
adds ${basedir}/bin to the PATH of the system command.
<property name="browser" location="C:/Programme/Internet Explorer/iexplore.exe"/>
<property name="file" location="ant/docs/manual/index.html"/>
 
<exec executable="${browser}" spawn="true">
    <arg value="${file}"/>
</exec>
Starts the ${browser} with the specified ${file} and end the ant process. The browser will let be open.
<exec executable="cat">
    <redirector outputproperty="redirector.out"
                errorproperty="redirector.err"
                inputstring="blah before blah">
        <inputfilterchain>
            <replacestring from="before" to="after"/>
        </inputfilterchain>
        <outputmapper type="merge" to="redirector.out"/>
        <errormapper type="merge" to="redirector.err"/>
    </redirector>
</exec>
Sends the string "blah before blah" to the "cat" executable, using an <inputfilterchain>to replace "before" with "after" on the way in. Output is sent to thefile "redirector.out" and stored in a property of the same name.Similarly, error output is sent to a file and a property, both named"redirector.err".
Note: Although it maywork for you to specify arguments using a simple arg-element andseparate them by spaces it may fail if you switch to a newer version ofthe JDK. JDK < 1.2 will pass these as separate arguments to theprogram you are calling, JDK >= 1.2 will pass them as a singleargument and cause most calls to fail.
Note2:If you are using Ant on Windows and a new DOS-Window pops up for everycommand which is executed this may be a problem of the JDK you areusing. This problem may occur with all JDK's < 1.2.
Timeouts: Ifa timeout is specified, when it is reached the sub process is killedand a message printed to the log. The return value of the executionwill be "-1", which will halt the build if failonerror=true, but be ignored otherwise.