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 9248723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:00:39+00:00 2026-06-18T10:00:39+00:00

I am writing a manifest.xml file during an Ant build for an OpenCMS project.

  • 0

I am writing a manifest.xml file during an Ant build for an OpenCMS project.

I need to be able to pull up a file’s create date, and last modified date on a file. (Although the current process is giving each file a timestamp of Wed, 31 Dec 1969 19:00:00 EST anyway — at least on Windows machines when they run the build.)

Is there a way I can pull up the creation date timestamp of a file in Ant? I’m using standard Ant tasks and Ant-Contrib tasks.

  • 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-18T10:00:40+00:00Added an answer on June 18, 2026 at 10:00 am

    It depends on your OS, f.e. Unix doesn’t store the file creation time, see details here
    Two possible solutions :

    Solution 1, works on Windows only with Java >= 6, no addons needed

    <project>
      <!-- Works on Windows only, uses the jdk builtin
           rhino javascript engine (since jdk6)
           use dir command without /T:C to get lastmodificationtime
      -->
      <macrodef name="getFileTimes">
        <attribute name="dir" />
        <attribute name="file" />
        <attribute name="setprop" default="@{file}_ctime" />
        <sequential>
          <exec executable="cmd" dir="@{dir}" outputproperty="@{setprop}">
            <arg value="/c" />
            <arg line="dir @{file} /T:C|find ' @{file}'" />
          </exec>
          <script language="javascript">
         tmp = project.getProperty("@{setprop}").split("\\s+") ;
         project.setProperty("@{setprop}", tmp[0] + "/" + tmp[1]) ;
       </script>
        </sequential>
      </macrodef>
    
      <getFileTimes dir="C:/tmp" file="bookmarks.html" />
    
      <echo>
      $${bookmarks.html_ctime} => ${bookmarks.html_ctime}
      </echo>
    </project>
    

    Solution 2, needs Java 7 and groovy-all-x.x.x.jar (contained in groovy binary release)
    Adjust the SimpleDateFormat to your liking.
    On Unix filesystems when asking for creationtime you’ll get the last modification time.

    <project>
      <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy"/>
    
      <!-- Solution for Java 7, uses the nio package
           needs groovy-all-2.1.0.jar
      -->
      <macrodef name="getFileTimes">
        <attribute name="file"/>
        <attribute name="ctimeprop" default="@{file}_ctime"/>
        <attribute name="mtimeprop" default="@{file}_mtime"/>
        <sequential>
          <groovy>
          import java.nio.file.*
          import java.nio.file.attribute.*
          import java.text.*
          import java.util.date.*
    
          Path path = Paths.get("@{file}")
          BasicFileAttributeView view = Files.getFileAttributeView(path, BasicFileAttributeView.class)
          BasicFileAttributes attributes = view.readAttributes()
          lastModifiedTime = attributes.lastModifiedTime()
          createTime = attributes.creationTime()
          DateFormat df = new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss", Locale.US)
          df.format(new Date(createTime.toMillis()))
    
          properties.'@{ctimeprop}' = df.format(new Date(createTime.toMillis()))
          properties.'@{mtimeprop}' = df.format(new Date(lastModifiedTime.toMillis()))
         </groovy>
        </sequential>
      </macrodef>
    
      <getFileTimes file="C:/tmp/bookmarks.html"/>
    
      <echo>
        $${C:/tmp/bookmarks.html_ctime} => ${C:/tmp/bookmarks.html_ctime}
        $${C:/tmp/bookmarks.html_mtime} => ${C:/tmp/bookmarks.html_mtime}
      </echo>
    </project>
    

    I tried also using the builtin javascript engine, but i got errors like :

    sun.org.mozilla.javascript.internal.EvaluatorException: missing name after . operator
    

    IMO, for simple things using javascript <script language="javascript"> is sufficient, but if you need to import java packages etc. .. it’s a PITA. Groovy simply works.

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

Sidebar

Related Questions

I'm writing an Ant build.xml file for an executable JAR for the first time,
This is the last part of my build: Generating the cache manifest - Command:
I'm writing a game with LibGDX, and I'm trying to save an XML file,
I'm writing a windows application that is embed with a manifest considering UAC in
I came across the following two lines in AndroidMenifest.xml file of my android application:
I'm writing a Chrome extension which should apply XSLT transform to certain XML documents
I'm writing a little WPF utility to manage entries in the hosts file for
I am writing a custom library. It's build into a .jar archive. I am
I have a custom file type that I'm reading from and writing to within
If I set in the Manifest.xml and try to install the .apk with ecclipse,

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.