java - 如何知道目标在 Ant 中执行所花费的时间

标签 java ant

<分区>

有没有办法知道目标执行所需的时间并将该时间存储在 ant 脚本的属性中。我已经检查了 tstamp 和秒表,但没有得到正确的结果。 示例:

 <target name ="test">
   .....
   .....
  </target>

我想知道目标“测试”执行所花费的时间。

最佳答案

您提到了 stopwatch包含在 Ant Contrib 中的任务.

我使用它没有任何问题。首先,您定义一个秒表并为其分配一个名称。在目标结束时,您使用 total 秒表操作。然后将耗时存储到与创建秒表时使用的名称相同的属性中。

<project name="Stopwatch">
  <!--
    Import Ant Contrib
  -->
  <taskdef resource="net/sf/antcontrib/antcontrib.properties">
    <classpath>
      <pathelement location="lib/ant-contrib-1.0b3.jar"/>
    </classpath>
  </taskdef>

  <!-- 
    Demonstrates the use of the stopwatch task.
    Creates a stopwatch named "timer1", do some work and then take the total
    time. The time is then stored in property "timer1".    
  -->
  <target name="teststopwatch">
    <stopwatch name="timer1"/>
    <echo message="Hello" />
    <stopwatch name="timer1" action="total" />
    <echo message="Total time: ${timer1}" />
  </target>
</project>

输出是:

Buildfile: /home/[...]/StopwatchTest/build_stopwatch.xml
teststopwatch:
     [echo] Hello
[stopwatch] [timer1: 0.012 sec]
     [echo] Total time: 0.012 sec
BUILD SUCCESSFUL
Total time: 564 milliseconds

关于java - 如何知道目标在 Ant 中执行所花费的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20779141/

相关文章:

php - 通过 Jenkins 运行 phpunit 测试时如何设置 $_SERVER [' ' ] 变量

java - 请参阅 ANT 构建文件中的外部资源

java - 如何确定您的网络应用程序是否无法连接互联网

java - 使用/Java Web 服务器返回文件时出错

netbeans - 如何将Netbeans项目添加为Gradle项目的依赖项?

ant - ANT 中有没有一种方法可以从 JAR 中提取一个类文件并将其放入另一个 JAR 中?

java - Ant - 任务和目标之间的区别

java - JDK 1.5 问题 - boolean 属性的 getter 方法被错误地调用

Java 子进程额外输出到控制台

java - 尝试在图形中绘制图像图标,但它不起作用