Java Constant Analyzer#

The Java Source Code Analyzer for Constants parses java source code to generate the dependencies between Java classes that are based on constants. The Java compiler inlines the constants. As a result, the relationship between the definition of constants and their references cannot be seen in Java byte code. Java defines constants as those data members of Java classes that are declared “static” and “final”. In addition, Java also treats data members defined within interfaces as “static” and “final”.

Running the Java Constant Analyzer#

Invoke the Java Constant Analyzer using the batch file jconanal.bat (for windows). Note that the Java Source Code Analyzer requires the use of JDK. It will not run with just Java JRE. It has been tested with JDK 1.6. It will not work with JDK 1.5. The batch may have to be modified to run with JDK 1.7. If you don’t have a JDK then you must download and install it.

The script looks for the JDK as follows:

  1. It will use the JAVA_HOME variable if it is already set.

  2. If JAVA_HOME is not set, it will look to use C:Program Filesjdk1.6.0_*.

Please edit the batch file if this does not work for your configuration.

Command Line Arguments#

The Java Source Code Analyzer for Constants takes the following arguments:

jconanal [-srcdir input-directory] | [-srcfile input-file] [-output output-file] [-memberlevel] [-help]

-srcdir: Specify the directory to be analyzed. All .java files in the specified directory will be analyzed.

-srcfile: Specify file to be analyzed

-output: Specify the file for the output. If the output file name is of type “ldi”, the format of the output will be for ldi. If the output file name is of type “csv”, the format of the file will be csv (comma separated values). Note that csv files can be read into excel directly. If you do not specify the output option, dependencies will be dumpled out on the console in a text format.

-memberlevel: The source/consumer and the target/provider of the dependencies will be down to the member level i.e. method and data members. If this option is not specified, the dependencies will be class to class.

-help: Simply outputs the command line.