File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Don't know if its art, but I need to know! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Don Watch "Don New topic

Don't know if its art, but I need to know!

Aaron Roberts
Ranch Hand

Joined: Sep 10, 2002
Posts: 174
In C and C++ compilers there are often preprocessor commands. I am trying to duplicate some of the functionality I'm used to in other languages. Examples of things I would like to do -
- Be able to reference the build/compile time in my code
- Same as above but for the date
- Reference the line number the compiler is at
I know there are others, but I can't think of specifics right now. Some pseudo code in C/C++ demonstrating the above might be

Where __CTIME__ and #COMP_TIME are the compile time parameters.
Any thoughts?
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Of course, u can use java.util.GregorianCalendar class to do things with the Time and Date stuff...
Java does have java.lang.Runtime class to deal with the low level commands as well... But there is a limitation on how low Java can dig into the system...

Co-author of SCMAD Exam Guide, Author of JMADPlus
Aaron Roberts
Ranch Hand

Joined: Sep 10, 2002
Posts: 174
I realize I can do date and time things, but the idea here is that the compiler is replacing, statically, those variable names. If today was Monday, 11 Jan 2004, then the __CTIME__ would be replaced during the compile only with that value. Its nothing that happens at runtime per se.
Its not something which is done very often, but when you need it, its handy to have.
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
I guess u might have to use Java Native Interface to apply the C/C++ native variables in the program...
I'm not that sure... But there are experts in the Other Java APIs forum who can help u in dealing with those native stuff...
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
As Java has no preparser such constructs are not available.
In C(++) the construct you mention would technically NOT give you the compilation time but the time the preparser was run at. This does not have to be the compilation time (it is possible to run only the preparser, and in large projects or on slow computers it is quite possible that there is a considerable (in machine terms) gap of several seconds if not longer between the preparser running and the compiler running.

Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
We are using Ant to do this. Basically, we do have a template file named Version.src with some java code declaring constants and placeholders for the actual values. The Ant script will copy the file to a file, thereby replacing the placeholders with actual values (using filters). Than the code gets compiled and other classes are able to refer to the constants with the current values.
Did that help?

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
I agree. Here's the link:
subject: Don't know if its art, but I need to know!
It's not a secret anymore!