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
create your own custom anttask. It's really not that difficult; http://ant.apache.org/manual/develop.html
Use the Maven exec plugin to execute Java to do this: http://mojo.codehaus.org/exec-maven-plugin/
精彩评论