JContractor facilitates building of Software based on the Design by Contract paradigm. JContractor is a tool that
allows for runtime verification of the contracts. JContractor is pure Java library i.e. it does not depend on
anything Operating system specific.
For a more detailed explanation of JContractor please visit the JContractor website
Requirements for running JContractor:
-
Java Software Development Kit. Download the latest version here
- JContractor library. Download it here
Running JContractor
JContractor can be run in two ways:
- Using jContractor class: This method runs your class using jContractor class that comes as a part of the
jContractor library. This does not involve any modification to your class files.
Usage: $> java jContractor [options] YourClass
Please note YourClass should have a main method.
-
Using jInstrument class: This method alters your class files or alternately generates new class files with modified
bytecode. It adds bytecode to ensure preconditions, postconditions and class invariants are checked when
constructors and/or methods are executed.
This involves 2 steps:
- Altering your class files or generating new class files using the jInstrument class.
- Running your class files or the newly generated class files in the usual way ($> java className).
Setting the classpath: Running jContractor in either of the two methods requires jcontractor.jar to be
available in your classpath. This setting can be done in 2 ways:
- Using the -cp command line argument to java and javac. Usage: For compiling: $>javac -cp
pathToJContractor.jar otherArguments.
For running $> java -cp pathToJContractor.jar otherArguments
- Using the CLASSPATH environment variable: Append the path to jcontractor.jar to your CLASSPATH
environment variable. *nix users using bash shell can add the following line to their .bash_profile file. export
CLASSPATH=$CLASSPATH:/path/to/jcontractor/jcontractor.jar