<PROJECT name="diagnostic"
basedir=".">
Operating system name:
${os.name}" />
$ ant -f diagnostic.xml现在,假如哪个方面出现了问题,你就可以在系统属性中找到问题的源头了,比如错误的Java版本或者类路径等等。
Buildfile: diagnostic.xml
systemProperties:
[echo] Java Runtime Environment version:
1.4.2_05
[echo] Java Runtime Environment vendor:
Apple Computer, Inc.
[echo] Java Runtime Environment vendor URL:
http://apple.com/
...
[echo] Default temp file path: /tmp
[echo] Operating system name: Mac OS X
[echo] Operating system architecture: ppc
[echo] Operating system version: 10.3.9
property="fop.available"/>
property="scriptsdir.exists"/>
unless="fop.available">
depends="files" unless="scriptsdir.exists">
import org.apache.tools.ant.*;
/**
JavaVersionTask is an Ant task for testing if
the installed Java version is greater than a
minimum required version.
**/
public class JavaVersionTask extends Task {
// Minimum required Java version.
private String minVersion;
// Installed Java version.
private String installedVersion;
// The name of the property that gets set when
// the installed Java version is ok.
private String propertyName;
/**
* ConstrUCtor of the JavaVersionTask class.
**/
public JavaVersionTask() {
super();
installedVersion = System.getProperty
("java.version");
}
/**
* Set the attribute minVersion.
**/
public void setMinVersion(String version) {
minVersion = version;
}
/**
Set the property name that the task sets when
the installed Java version is ok.
**/
public void setProperty(String propName) {
propertyName = propName;
}
/**
* Execute the task.
**/
public void execute() throws BuildException {
if (propertyName==null) {
throw new BuildException("No property name
set.");
} else if (minVersion==null) {
throw new BuildException("No minimum version
set.");
}
if(installedVersion.compareTo(minVersion)
>= 0) {
getProject().setProperty(propertyName,
"true");
}
}
}
classname="JavaVersionTask" classpath="."/>
property="javaversion.ok"/>
unless="javaversion.ok">
javaVersion: [echo] ERROR: Java version与JavaVersionTask相似,我们也可以写一个任务来执行其他的版本检查,例如已安装的库或者操作系统的版本。
too old: found 1.4.2_05, needs 1.5.
unless="binary.unchanged">
unless="config.unchanged">
checksum:
[echo] Verifying checksums of binary files...
[echo] Verifying checksum of configuration file...
binaryChanged:
configChanged:
all:
BUILD SUCCESSFUL
Total time: 1 second
checksum:
[echo] Verifying checksums of binary files...
[echo] Verifying checksum of configuration file...
binaryChanged:
configChanged:
[echo] WARNING: Configuration file changed.
all:
BUILD SUCCESSFUL
Total time: 1 second
depends="checksum" unless="config.unchanged">
addproperty="config.restore"/>
depends="configChanged" if="config.copy">
tofile="build/config.xml.1" overwrite="true"/>
overwrite="true"/>
新闻热点
疑难解答