What command and Java
November 17, 2013
We have our Java code marked with a version constant, where the value is prefixed by @(#)
:
public static final String __VERSION__ = "@(#)$Id$";
This is expanded by CVS automatically at commit time, so it contains the cvs file version - something like:
public static final String __VERSION__ = "@(#)$Id: ClassName.java,v 1.5 2004/07/01 16:37:53 drumcoder Exp $";
There is a command in Unix called what
, which is part of SCCS (an archaic version control system) which will take a binary file, look for a string that starts @(#)
and print out that string.
You can therefore use this on a java .class
file to find out the VERSION constant value at the time the file was compiled, and see if it's the version you expect.
what filename.ext
Modern linux doesn't come with SCCS, and so that what
command is unavailable. It can be faked with:
strings filename.ext | grep '@(#)'
We can extend this to operate on a jar file, printing out the VERSION
value for each .class
file in the jar:
unzip -c filename.jar | strings | grep '@(#)'
The -c
option in this case extracts the files in the jar file to stdout, and they are then piped through strings
and grep
.