Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing variable value from java to ant to be read as property

 
Kajal Sharma
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a java code where I am calculating the current time stamp as follows:
int mon = rightNow.get(Calendar.MONTH) + 1;
if (mon < 10)
str += "0" + mon;
else
str += mon;
int day = rightNow.get(Calendar.DAY_OF_MONTH);
if (day < 10)
str += "0" + day;
else
str += day;
int hr = rightNow.get(Calendar.HOUR_OF_DAY);
if (hr < 10)
str += "0" + hr;
else
str += hr;
int min = rightNow.get(Calendar.MINUTE);
if (min < 10)
str += "0" + min;
else
str += min;
return(str);

Now I need final value to be set as a ant property .

Please help
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

Firstly a quick Admin issue, can you please edit your post to include code tags, it will help us read the question easier

Now onto your question, you _might_ be able to use the output property of the Java task, see details

I've never tried it myself mind you!
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18012
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm afraid you didn't mention how you were getting from Java into Ant. However, there are much simpler ways to format dates than by building them up with low-level string code.

I'd also verify that the Ant datestamp task doesn't already do what you need without requiring extra Java code.
 
Kajal Sharma
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using ant script to create the jad and jar file. In that I need to log the build date in text file. The same build date is required to be logged in the jad and manifest file. So, I need the same value which was generated by java code, to be used while building jar package.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kajal,
The first thing that comes to mind is have the Java program write the value into a file for the Ant script to read later.

It seems easier to have Ant generate the timestamp and pass it to Java though.
 
Kajal Sharma
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand that its better to use timestamp from ant. But the I log time to the level of seconds. That is why I require the time which is written by java code in the file.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kajal,
Ant's timestamp task does timestamps to the second (or millisecond.) You just have to pass a parameter to say you want it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic