Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to store compile time data in Java

 
Avinash Rai
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All
Is there any way to store compile time data in Java?
For example I want to compile one class which displays today's date and time. I am using Calender class to do this.
And This today's date is displayed in About box of my application.
But what is happening is if I open my application 4 days from now it displays the date current on that day and not today's date when I compiled my application.
I know all objects are created at runtime in Java.
But was interested does any one knows a trick on how to do this.
Thanks
Avinash.
 
Blake Minghelli
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, just a thought off the top of my head... there's probably a better way of doing it...
Your build process could include the execution of a java program that generates another java class that stores the compile time date. For example, the program would use a PrintWriter to actually write a java source file that contains a static constant that is initialized with the current date. Like this:

Your build routine can compile the new HelpInfo source file and include it in your release. Then, your "About" frame could get the compile date via HelpInfo.COMPILE_DATE.
Good luck!
[ October 16, 2002: Message edited by: Blake Minghelli ]
 
Lewin Chan
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a similar idea, why not have a properties file that is generated by your build process that has a timestamp in it,
Then you can just use that pre-defined property as the source of your "about box"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic