ant 编译java_ant 编译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. See notes below for more details.

Either jar or classname

args

the arguments for the class that is executed. deprecated, use nested elements instead.

No

classpath

the classpath to use.

No

classpathref

the classpath to use, given as referenceto 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 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 failοnerrοr=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

clonevm

If set to true true, then all system properties and the bootclasspath of the forked Java Virtual Machine will be the same as those of the Java VM running Ant. Default is "false" (ignored if fork is disabled). since Ant 1.7

No

Parameters specified as nested elements

arg and jvmarg

Use nested and elements to specify arguments for the Java class and the forked VM respectively. See Command line arguments.

sysproperty

Use nested 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 structureand 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 do not specify permissions, a set of default permissions will be added to your Java invocation to make sure that the ant run will continue or terminated as indicated by failonerror. All permissions not granted per default will be checked by whatever security manager was already in place. exitVM will be disallowed.

Settings will be ignored if fork is enabled.

since Ant 1.6.

assertions

You can control enablement of Java 1.4 assertions with an 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 behave as the corresponding attributes available at the task level. The most notable peculiarity stems from the retention of the attributes for backwards compatibility. Any file mapping is done using a null sourcefile; therefore not all Mappertypes 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 codesBy default the return code of a 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 failοnerrοr="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 failοnerrοr="false" and fork="false" , then must return 0 otherwise the build will exit, as the class was run by the build JVM.

JAR file execution

The parameter of the jar attribute is of type File; that is, the parameter is resolved to an absolute file relative to the base directory of the project, not the directory in which the Java task is run. If you need to locate a JAR file relative to the directory the task will be run in, you need to explicitly create the full path to the JAR file.

When using the jar attribute, all classpath settings are ignored according to Sun's specification.

Examples

Run a class in this JVM with a new jar on the classpath

fork="true"

failοnerrοr="true"

maxmemory="128m"

>

Run the JAR test.jar in this project's dist/lib directory. using the manifest supplied entry point, forking (as required), and with a maximum memory of 128MB. Any non zero return code breaks the build.

dir="${exec.dir}"

jar="${exec.dir}/dist/test.jar"

fork="true"

failοnerrοr="true"

maxmemory="128m"

>

Run the JAR dist/test.jar relative to the directory ${exec.dir}, this being the same directory into which the JVM is to start up. Runs a given class with the current classpath.

fork="yes" >

Add system properties and JVM-properties to the JVM as in java ="-Xrunhprof:cpu=samples,file=log.txt,depth=3 -DDEBUG=true test.Main

jvm="path-to-java14-home/bin/java" fork="true"

taskname="java1.4" >Use a given Java implementation (another the one Ant is currently using) to run the class. For documentation in the log taskname is used to change the [java] log-prefix to [java1.4].

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 if required.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值