- 浏览: 53570 次
- 性别:
- 来自: 珠海
-
文章分类
最新评论
ANT启动脚本详细说明
广告靠左。文字在右
<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.
The
source and destination directory will be recursively scanned for Java
source 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 the
classes that need a rebuild. It will not scan the source and therefore
will have no knowledge about nested classes, classes that are named
different 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 excludesfile
attribute is used to specify the files you want to have excluded. In
both 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
andjavac1.2
can be used as aliases. -
modern
(the standard compiler of JDK 1.3/1.4/1.5) –javac1.3
andjavac1.4
andjavac1.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 x
depending on the JDK version you use while you are running Ant. If you
wish to use a different compiler interface than those supplied, you can
write 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 you
will 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 wildcard
patterns) that must be excluded; no files (except default excludes) are
excluded 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:none
will be passed on the command line for compilers that support it (for
other 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 ). Note
that the default value depends on the JVM that is running Ant. In
particular, if you use JDK 1.4+ the generated classes will not be
usable for a 1.1 Java VM unless you explicitly set this attribute to
the value 1.1 (which is the default value for JDK 1.1 to 1.3). We
highly 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
|
Exactly one of these.
|
|
line
|
||
file
|
||
path
|
||
compiler
|
Only
pass the specified argument if the chosen compiler implementation
matches the value of this attribute. Legal values are the same as those
in 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/testpackage
directory are excluded from compilation. You didn't specify a source or
target level, so the actual values used will depend on which JDK you
ran 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>
If
you want to run the javac compiler of a different JDK, you should tell
Ant, where to find the compiler and which version of JDK you will be
using so it can choose the correct command line switches. The following
example executes a JDK 1.1 javac in a new process and uses the correct
command line switches even when Ant is running in a Java VM of a
different 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.If
you wish to compile only files explicitly specified and disable javac's
default searching mechanism then you can unset the sourcepath
attribute:
<javac sourcepath="" srcdir="${src}"
destdir="${build}" >
<include name="**/*.java"/>
<exclude name="**/Example.java"/>
</javac>
That
way the javac will compile all java source files under "${src}"
directory but skip the examples. The compiler will even produce errors
if 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 every
use of an external compiler, this may be a problem of the JDK you are
using. This problem may occur with all JDKs < 1.2.
Jikes Notes
You need Jikes 1.15 or later.
Jikes
supports some extra options, which can be set be defining the
properties shown below prior to invoking the task. The setting for each
property will be in affect for all
<javac>
tasks throughout the build. The Ant developers are aware that this is
ugly and inflexible – expect a better solution in the future. All the
options 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
|
the
location of the jar file to execute (must have a Main-Class entry in
the 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
|
the
command used to invoke the Java Virtual Machine, default is 'java'. The
command is resolved by java.lang.Runtime.exec(). Ignored if fork is
disabled.
|
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
|
The
name of a property in which the return code of the command should be
stored. 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
|
Name
of a file to which to write the output. If the error stream is not also
redirected 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
|
This
attribute is used when you wish to see error output in Ant's log and
you are redirecting output to a file/property. The error output will
not be included in the output file/property. If you redirect error with
the "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
|
The
name 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
|
A
file from which the executed command's standard input is taken. This
attribute is mutually exclusive with the inputstring attribute
|
No; default is to take standard input from console (unless
spawn="true" ) |
inputstring
|
A
string which serves as the input stream for the executed command. This
attribute 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. These
properties will be made available to the VM during the execution of the
class (either ANT's VM or the forked VM). The attributes for this
element 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
When
the permission RuntimePermission exitVM has not been granted (or has
been revoked) the System.exit() call will be intercepted and treated
like indicated in failonerror.
Note: if you specify
failonerror="true"
and you do not specify permissions, a set of default permissions will
be added to your Java invocation to make sure that a non-zero return
code 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 Redirector
can be specified. In general, the attributes of the redirector behave
as the corresponding attributes available at the task level. The most
notable peculiarity stems from the retention of the <java>
attributes for backwards compatibility. Any file mapping is done using
a
null
sourcefile; therefore not all Mapper
types will return results. When no results are returned, redirection
specifications will fall back to the task level attributes. In practice
this means that defaults can be specified for input, output, and error
output 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>
Run
the jar using the manifest supplied entry point, forking (as required),
and with a maximum memory of 128MB. Any non zero return code breaks the
build.
<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 the
JVM, as it takes different parameters for other JVMs, That JVM can be
started 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.
Note
that you cannot interact with the forked program, the only way to send
input to it is via the input and inputstring attributes. Also note that
in Ant 1.6, any attempt to read input in the forked program will
receive an EOF (-1). This is a change from Ant 1.5, where such an
attempt 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 the
call. In particular, if you do not put a file extension on the
executable, only ".EXE" files are looked for, not ".COM", ".CMD" or
other file types listed in the environment variable PATHEXT. That is
only used by the shell. Cygwin Users
In general the
<exec>
task will not understand paths such as /bin/sh for the executable
parameter. This is because the Java VM in which Ant is running is a
Windows 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). Please
note that the Java VM provided by HP doesn't follow OpenVMS'
conventions of exit codes. If you run a Java VM with this task, the
task may falsely claim that an error occured (or silently ignore an
error). 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-LISTSERV
that shell scripts invoked via the Ant Exec task must have their
interpreter specified, i.e., the scripts must start with something
like:
#!/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
|
list
of Operating Systems on which the command may be executed. If the
current OS's name is contained in this list, the command will be
executed. The OS's name is determined by the Java Virtual machine and
is 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
|
Name
of a file to which to write the output. If the error stream is not also
redirected 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
|
This
attribute is used when you wish to see error output in Ant's log and
you are redirecting output to a file/property. The error output will
not be included in the output file/property. If you redirect error with
the "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
|
The
name 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
|
A
file from which the executed command's standard input is taken. This
attribute is mutually exclusive with the inputstring attribute. since Ant 1.6
|
No
|
inputstring
|
A
string which serves as the input stream for the executed command. This
attribute 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
|
Run
command using the Java VM's execution facilities where available. If
set to false the underlying OS's shell, either directly or through the
antRun scripts, will be used. Under some operating systems, this gives
access to facilities not normally available through the VM including,
under Windows, being able to execute scripts, rather than their
associated interpreter. If you want to specify the name of the
executable as a relative path to the directory given by the dir
attribute, it may become necessary to set vmlauncher to false as well.
|
No, default is true
|
resolveexecutable
|
When
this attribute is true, the name of the executable is resolved firstly
against the project basedir and if that does not exist, against the
execution directory if specified. On Unix systems, if you only want to
allow execution of commands in the user's path, set this to false. since Ant 1.6
|
No, default is false
|
searchpath
|
When
this attribute is true nested, then system path environment variables
will 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
|
The
value for a PATH like environment variable. You can use ; or : as path
separators 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 Redirector
can be specified. In general, the attributes of the redirector behave
as the corresponding attributes available at the task level. The most
notable peculiarity stems from the retention of the <exec>
attributes for backwards compatibility. Any file mapping is done using
a
null
sourcefile; therefore not all Mapper
types will return results. When no results are returned, redirection
specifications will fall back to the task level attributes. In practice
this means that defaults can be specified for input, output, and error
output 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. What
do those error codes mean? Well, they are OS dependent. On Windows
boxes you have to look in include/error.h in your windows compiler or
wine files; error code 2 means 'no such program', which usually means
it is not on the path. Any time you see such an error from any ant
task, it is usually not an ant bug, but some configuration problem on
your 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 the
file "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 may
work for you to specify arguments using a simple arg-element and
separate them by spaces it may fail if you switch to a newer version of
the JDK. JDK < 1.2 will pass these as separate arguments to the
program you are calling, JDK >= 1.2 will pass them as a single
argument and cause most calls to fail.
Note2:
If you are using Ant on Windows and a new DOS-Window pops up for every
command which is executed this may be a problem of the JDK you are
using. This problem may occur with all JDK's < 1.2.
Timeouts: If
a timeout is specified, when it is reached the sub process is killed
and a message printed to the log. The return value of the execution
will be "-1", which will halt the build if failonerror=true, but be ignored otherwise.
相关推荐
在"Ant和批处理脚本.rar"这个压缩包中,可能包含了Ant的构建文件示例、批处理脚本模板,以及相关的说明文档。用户可以通过学习这些示例,了解如何编写自己的Ant构建脚本和批处理脚本,从而提升开发效率。同时,这也...
对于Web应用,可能需要启动如Tomcat这样的服务器,这通常通过执行服务器的启动脚本来完成,可以在Ant中用`exec`任务来实现。 **部署**: 在Java Web应用中,部署通常意味着将WAR或EAR文件复制到应用服务器的webapps...
本文将深入探讨如何使用Ant将Java工程打包成bat可执行文件,并结合提供的`antBatTest`压缩包中的示例进行说明。 首先,我们需要了解Ant的基本概念。Ant是一个基于XML的构建工具,它的主要任务是编译、测试、打包和...
5. `README`文件:简要说明如何安装和使用Ant。 使用Ant时,通常需要将其添加到系统的PATH环境变量中,以便在命令行中直接调用。然后,开发者可以根据项目的具体需求编写build.xml文件,配置构建过程。通过执行`ant...
1. "ant-launcher-1.6.3.jar" - 这是Ant启动器的主要文件,它包含了运行Ant构建脚本所需的类和资源。Ant启动器允许用户执行Ant构建文件(build.xml)而无需单独安装完整的Ant环境。 2. "ant.license.txt" - 这个文件...
Ant以其XML格式的构建文件(build.xml)而闻名,这个文件详细描述了构建任务和依赖关系。在"java ant集成1.9.5版本"中,我们主要讨论的是如何将Apache Ant 1.9.5集成到Java开发环境中。 Apache Ant 1.9.5是该工具的...
3. **LICENSE**: 此文件包含Apache Ant的许可协议,详细说明了软件的使用、复制和分发的条款。Apache Ant遵循Apache License 2.0,这是一个宽松的开源许可,允许商业使用。 4. **NOTICE**: 这个文件列出了Apache ...
1. **bin**:包含启动Ant的脚本文件,如`ant`和`ant.bat`,分别用于Unix/Linux和Windows系统。 2. **lib**:存放Ant运行时依赖的JAR文件,包括Ant核心库和其他扩展库。 3. **docs**:提供Ant的用户指南、API文档以及...
6. **启动和构建脚本**:如`npm run dev`用于开发环境的热更新,`npm run build`用于生产环境的打包优化。这些脚本在`package.json`的`scripts`字段中定义。 7. **文档**:可能包含README.md或其他说明文档,用于...
`使用说明.txt`文件应该包含了如何运行这个自动备份程序的详细步骤,可能包括如何编辑`build.xml`来定制备份配置,如何修改`start.bat`以设置定时任务,以及如何启动和停止备份服务。 在实际应用中,`build.xml`...
Apache Ant 是一个广泛使用的Java构建工具,它基于XML来定义项目构建过程,使得构建脚本具有高度可读性和可移植性。本篇文章将详细介绍Ant的API、安装步骤以及如何使用个人编辑过的`build.xml`文件。 一、Apache ...
这通常是开源软件的许可证文件,详细说明了Ant的许可协议,即Apache License 2.0。根据这份许可证,任何人都可以自由地使用、修改和分发Ant,只要保留原有的版权信息并遵循开源协议的规定。 在实际应用中,"ant-...
《北京尚控科技有限公司Ant-6143说明书》是一份详细解读Ant-6143产品功能、操作方法及维护指南的重要文档。该说明书主要针对Ant-6143设备,由专业IT公司——北京尚控科技有限公司提供,旨在帮助用户充分理解和有效地...
1. `bin` 目录:包含Ant的可执行脚本(如ant.bat和ant.sh),这些脚本用于启动Ant。 2. `lib` 目录:存放ant.jar和其他必需的库文件。 3. `docs` 目录:包含各种文档,如HTML格式的用户指南和任务参考。 4. `src` ...
1. **bin目录**:包含可执行脚本,如`ant`和`ant.bat`,分别用于Unix/Linux和Windows环境启动Ant。这些脚本允许用户在命令行中执行构建任务。 2. **lib目录**:包含Ant运行所需的库文件,如JAR文件。这些库文件支持...
【Jmeter+ant+Jenkins集成接口自动化测试详解】 接口自动化测试在现代软件开发中扮演着重要的角色,它能够提高测试效率,确保系统的稳定性和可靠性。JMeter是一款强大的开源性能测试工具,通常用于接口压力测试,但...
3. **bin** 目录:包含可执行脚本,如`ant`或`ant.bat`,用于启动Ant构建过程。 4. **manual** 或 **docs** 目录:包含Ant的文档,帮助开发者理解如何使用各个任务和属性。 Ant 的主要优点在于它的灵活性和可扩展性...
总结来说,"ant-launcher-1.7.1.jar.zip"是一个包含Apache Ant启动器1.7.1版本的压缩文件,它使得开发者能够在命令行环境中运行Ant构建任务。同时,提供的`ant.license.txt`文件确保用户了解并同意使用该软件的许可...
1. `bin`目录:包含了Ant的可执行脚本,如`ant`和`ant.bat`,分别用于Unix/Linux和Windows平台启动Ant。 2. `lib`目录:存放Ant运行时所需的JAR文件,包括Ant的核心库和其他依赖库。 3. `docs`目录:包含Ant的用户...
1. **构建脚本**:Ant使用XML格式的build.xml文件作为构建脚本,其中包含了构建过程的详细步骤。例如,`<target>`标签用于定义一个任务,`<javac>`标签用于编译Java源代码,`<jar>`标签则用于打包编译后的类文件到...