开发者

Storing a UNIX Timestamp in an Ant Property?

开发者 https://www.devze.com 2023-02-25 01:35 出处:网络
I\'d like to store a UNIX timestamp (i.e. seconds since epoch) in an Ant property for later use in a couple build targets. It appears to be impossible:

I'd like to store a UNIX timestamp (i.e. seconds since epoch) in an Ant property for later use in a couple build targets. It appears to be impossible:

<tstamp>
  <format property="build.time" />
</tstamp>`

...generates a formatted timestamp.

<propertyfile file="foo.properties">
    <entry key="build.time" type="date" default="now" />
</propertyfile>

...also generates a formatted timestamp.

I'd hope that this is possible without using <exec> or similar (since we will som开发者_如何学编程etimes run the build on Windows).


A quick google brings up:

http://www.norio.be/blog/2010/08/getting-unix-time-epoch-ant-build-file

<target name="print-epoch">
  <script language="javascript">
  <![CDATA[
    property = project.setProperty("now",Math.floor((new Date()).getTime()/1000));
  ]]>
  </script>
  <echo message="${now}" />
</target>

Other approaches that would be cleaner IMO would be to

  1. create your own custom anttask. It's really not that difficult; http://ant.apache.org/manual/develop.html

  2. Use the Maven exec plugin to execute Java to do this: http://mojo.codehaus.org/exec-maven-plugin/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号