aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes Passing variable value from java to ant to be read as property Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Passing variable value from java to ant to be read as property " Watch "Passing variable value from java to ant to be read as property " New topic
Author

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

Kajal Sharma
Greenhorn

Joined: Sep 19, 2008
Posts: 11
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

Joined: Jun 24, 2003
Posts: 3274
    
    5

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!


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16246
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Kajal Sharma
Greenhorn

Joined: Sep 19, 2008
Posts: 11
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

Joined: May 26, 2003
Posts: 30929
    
158

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Kajal Sharma
Greenhorn

Joined: Sep 19, 2008
Posts: 11
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

Joined: May 26, 2003
Posts: 30929
    
158

Kajal,
Ant's timestamp task does timestamps to the second (or millisecond.) You just have to pass a parameter to say you want it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing variable value from java to ant to be read as property