Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

The equivalent of __DATE__

933 views
Skip to first unread message

osa...@my-deja.com

unread,
May 28, 1999, 3:00:00 AM5/28/99
to
How do I retrieve the compilation date in a Java class?
What is the Java equivalent of this:

static char compDate[] = __DATE__;

Help appreciated.
/Ole
__
Ole Sandum, osa...@bigfoot.com
Enterprise Systems, http://www.es.dk


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

Dave Postill

unread,
May 28, 1999, 3:00:00 AM5/28/99
to
[This followup was posted to comp.lang.java.help, cc: the cited author, osa...@my-deja.com]

In article <7ilmhh$72i$1...@nnrp1.deja.com>, on Fri, 28 May 1999 09:10:09 GMT, osa...@my-deja.com
wrote:

> How do I retrieve the compilation date in a Java class?
> What is the Java equivalent of this:
>
> static char compDate[] = __DATE__;

I use a shell script [thanks to Emery Lapinski for the idea] that writes a versioning Java file:

#!d:\apps\mks\mksnt\sh.exe -f

if [ $# = 0 ]
then
PACKAGE="" ;
elif [ $# = 1 ]
then
PACKAGE="package $1;"
else
echo "Usage: makeversion [package]"
exit 1
fi

if [ \! -s .version ] ; then echo "Please make a .version file" 1>&2 ; exit 1 ; fi
VERSION=`cat .version`

if [ -s .build ] ; then BUILD=`cat .build` ; else BUILD=0 ; fi
BUILD=`echo $BUILD + 1 | bc`
echo $BUILD > .build

DATE=`d:/apps/mks/mksnt/date.exe +'%Y%m%d %T'`
USER=`d:/apps/reskit/whoami.exe`

cat << EOF
/*==================================================================================================

Name : JTVersion.java
Java : JDK $JAVA_VERSION, JFC $SWING_VERSION
Synopsis : Product version

Copyright &copy; 1998 <a href="mailto:davep...@pobox.com">Dave Postill</a>, All rights reserved

==================================================================================================*/

$PACKAGE

public final class JTVersion
{
/**
* Version number. Read from <tt>.version</tt>.
**/

public static final String VERSION = "$VERSION";

/**
* Build number. Incremented on each build and stored in <tt>.build</tt>
**/

public static final String BUILD = "$BUILD";

/**
* Build date/time.
**/

public static final String DATE = "$DATE";

/**
* User name of builder.
**/

public static final String USER = "$USERNAME";

/**
* Java version used for the build.
**/

public static final String JDK = "$JAVA_VERSION";

/**
* Swing version used for the build.
**/

public static final String JFC = "$SWING_VERSION";

/**
* Returns a string representation of this instance.
*
* @return a string representation of this instance.
**/

public String toString()
{
return "Version $VERSION $DATE JDK $JAVA_VERSION, JFC $SWING_VERSION (Build $BUILD/$USERNAME)";
}

/**
* Returns the version number.
*
* @return the version number.
**/

public String getVersionNumber()
{
return "$VERSION";
}

/**
* Returns the build number.
*
* @return the build number.
**/

public String getBuildNumber()
{
return "$BUILD";
}

/**
* Returns the build date.
*
* @return the build date.
**/

public String getDate()
{
return "$DATE";
}

/**
* Returns the user name of the builder.
*
* @return the user name of the builder.
**/

public String getUserName()
{
return "$USERNAME";
}

/**
* Returns the Java version used for the build.
*
* @return the Java version used for the build.
**/

public String getJavaVersion()
{
return "$JAVA_VERSION";
}

/**
* Returns the JFC version used for the build.
*
* @return the JFC version used for the build.
**/

public String getJFCVersion()
{
return "$SWING_VERSION";
}
}

//==== EOF =======================================================================================
EOF

And in the makefile:

JTVersion.java: force
makeversion uk.co.iisc.jtoolkit >! JTVersion.java


davep
--
Dave Postill Investment Intelligence Systems Corp
Galaxy Support Leader +44 (0) 171 628 6960 [voice]
<mailto:da...@iisc.co.uk> +44 (0) 171 638 7528 [fax]
<mailto:dave.p...@pobox.com> <http://www.iisc.co.uk>

0 new messages