Bytecode Version Inspector:
Command Line Application

Description

Bytecode Version Inspector examines class and jar files for Java version information. The tool will traverse a directory tree, and can report on either the individual Java version of each class file, or on the range of Java versions found in each directory or jar file. The tool is also available as an Ant task.

The application returns a result code of 0 for success, and various negative numbers for failure of one sort or another.

The application can be configured to produce a report, either to the console or to a file. The report can be generated in a standard format, either plain (ASCII text) or XML, or in a custom format.

Bytecode Versions

Java bytecode is the encoding used for class files, as output by a Java compiler. It is versioned separately from the Java language. The following table gives the bytecode versions that will run on a particular JVM version, as listed by Sun or determined by experiment.

Bytecode Version JVM Version Source
45.0 - 45.3 1.0.2 Sun
45.0 - 45.65535 1.1.* Sun
45.0 - 46.0 1.2 Sun; experiment suggests that some 1.2 JVMs also support 46.3
45.0 - 47.0 1.3 Experiment
45.0 - 48.0 1.4 Experiment
45.0 - 49.0 5 (1.5) Experiment

With this information, you can inspect your files to make sure they will run with a particular JVM. For example, if you want a particular jar file to run with any JVM from version 1.3 or later, you would inspect that jar file to make sure all bytecode versions for any class files in the jar lie in the range [45.0 .. 47.0].

Usage

Windows:
    bcver [flags] file [file]*

Unix:
    ./bcver.sh [flags] file [file]*

Java:
    java -jar bcver.jar [flags] file [file]*

The file arguments control which files are checked for version information. If a file argument represents a directory, all files in that directory are checked, and all files in any subdirectory, recursively (unless the -f switch has been specified). The file arguments do not expand wildcard characters.

Flag Description Required
-f ("flat") Do not traverse subdirectories when checking bytecode version numbers. No; at most one of these. Defaults to -r
-r Recursively traverse subdirectories when checking bytecode version numbers.
+d Print a summary for directories. The summary gives the maximum and minimum javacode versions found in class files in that directory, but not including subdirectories. No (defaults to +d).
-d Do not print a summary for directories.
+j Print a summary for archives (jar files). The summary gives the maximum and minimum javacode versions found in class files within the archive. No (defaults to +j).
-j Do not print a summary for archives (jar files).
+c Print information for individual classes. Each class gives the javacode version for which it was compiled. No (defaults to +c).
-c Do not print information for individual classes.
-max=version Cause a return code of -2 if any file encountered while inspecting version numbers has a version that is greater than the given version. No
-min=version Cause a return code of -3 if any file encountered while inspecting version numbers has a version that is smaller than the given version. No
-txt[=filename] Produce a text report, writing the results to the file if specified, or to standard output if no filename is specified. No
-xml[=filename] Produce an XML report, writing the results to the file if specified, or to standard output if no filename is specified. No
-rpt=class[=filename] Produce a custom report, writing the results to the file if specified, or to standard output if no filename is specified. The custom report formatter must implement com.bennettconsulting.bcver.ResultFormatter. No

The file arguments may each be a directory, an archive file, or a class file. For a class file, the tool reports the file's class version in major.minor format. Note that the class version does not match the JVM version that runs it; e.g., 48.0 class version will run on JVM 1.4 but not on JVM 1.3 or earlier.

For an archive, the tool reports the version number (as above) for each class file in the archive. Archive files must have a name ending in (Windows: have file extension of) ".jar", ".war", ".ear", ".zip", or ".sip".

For a directory, the tool reports the version number (as above) for each class file in the directory, any subdirectories, and any archives in the directory or subdirectories.

Examples

>bcver -d -j -txt build dist
48.0 build\java\com\bennettconsulting\bcver\VersionInspector.class
48.0 dist\bcver.jar[com/bennettconsulting/bcver/VersionInspector.class]

Check directories build and dist for class file versions. Write a text-formatted report to the console, do not generate a summary line for directories, and do not inspect within jar files.

License

This tool is distributed under the Apache 2.0 License. The license is also available on the web.