Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9005547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:10:27+00:00 2026-06-16T01:10:27+00:00

I am new to Ant, I have a scenario to assign a current time

  • 0

I am new to Ant, I have a scenario to assign a current time which I have got[1], while creating a folder[2] and down the file I add some file to the folder[3]. So there I need to get the value of time which I have got in [2]. I am basically a java guy, if it was in java it was few seconds job to have one global variable and re-using it. But here I am not sure how to reuse the value globally in different target tags. Kindly share your thought on this.

[1]

<macrodef  name="set.timestamp">
      <sequential>
         <tstamp>
            <format property="current.time" pattern="MM-dd-yyyy_hh-mm-ss"/>
        </tstamp>
      </sequential>
   </macrodef>

[2]

<target name="init" depends="setRuntimeArchive">
      <set.timestamp/>
      <mkdir dir="${results}/${classname}_${current.time}/xml" />
      <mkdir dir="${results}/${classname}_${current.time}/html" />
      <mkdir dir="${junit-report-output}" />
   </target>

[3]: Here I am not able to get current.time value as same as I got above [2]

<target name="runTestResults">
      <copy
         file="${eclipse-home}/${report}.xml"
         tofile="${results}/${classname}_${current.time}/xml/${report}_${platform}.xml"
         failonerror="false" />
      <xslt
         style="${etf-home}/plugins/${org.eclipse.test}/JUNIT.XSL"
         basedir="${results}/${classname}_${current.time}/xml"
         destdir="${results}/${classname}_${current.time}/html" />
      <antcall target="runTestStatus" />
   </target>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:10:29+00:00Added an answer on June 16, 2026 at 1:10 am

    In Ant, any task not in a target is executed before any targets. Therefore, all you have to do is set your property current.time outside of any targets, and that property will be available for all of your targets:

    <project name="foo" default="some.task" basedir=".">
        <tstamp>
            <format property="current.time"
                 pattern="MM-dd-yyyy_hh-mm-ss"/>
        </tstamp>
    
        <target name="run.test.status"
             depends="run.test.results">
             ...
        </target>
    
        <target name="run.test.results">
             <property name="results.dir" 
                 value="${results/${classname_$current.time}/xml"/>
             <mkdir dir="${results.dir}"/>
             <copy
                 file="${eclipse-home}/${report}.xml"
                 tofile="${results.dir}/${report}_${platform}.xml"
                 failonerror="false" />
             <xslt
                 style="${etf-home}/plugins/${org.eclipse.test}/JUNIT.XSL"
                 basedir="${results}/${classname}_${current.time}/xml"
                 destdir="${results}/${classname}_${current.time}/html" />
       </target>
    

    In the above, the time stamp is set when this build.xml is first executed since it’s not in any target. Now, the Timestamp is available in all targets.

    By the way, I set the property ${results.dir} to make it easier to read in StackOverflow since the directory name would otherwise extend beyond the edge of the page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Every time I create a new project I copy the last project's ant file
I have following script which is aim to make a war file. def ant
How do I add a new directory into my CVS repository using Ant? From
I am quite new to ant and have been looking at the tasks. I
I have an ant script to compile and generate an AIR file, and it
I'm new to ant, and I want to require a file name if something
I have a jar file I produced from compiled class files using an ant
im pretty new at Ant and have been looking for alot of examples. I
I'm new to NAnt but have some experience with Ant and CruiseControl. What I
I'm new to automating builds using Ant. I have a bunch of Android project

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.