When you start using JContractS you have to add a few additional steps to your build process. This is because JContractS and your other projects need differently built JAR files at different times. Below is a dataflow diagram of how your Java sources are transformed to, in this case, four sets of compiled classes. Each set has its own purpose:
The leftmost branch of the diagram represents the standard compilation of the Java sources. No changes are needed here. You can use the result of this branch if you do not want to use contracts at all.
As you can see each configuration of enabled contracts (preconditions and/or postconditions and/or invariants) needs its own branch of instrumented sources: the 2nd and fourth branches.
In addition a set of repository classes is generated. The repository classes are used by projects depending on this project to read the contracts of superclasses without needing access to the source code. The repository classes are the same for all configurations of enabled contracts.
The Java compiler and JContractS in the above diagram have to be applied in the following order:
Each step needs its own specific classpath. What is needed on the classpath is detailed below.
The following items must be on the classpath passed to the Java compiler:
The following items must be on the classpath used to run JContractS:
The following items must be on the classpath passed to the Java compiler:
The following items must be on the classpath passed to the Java compiler:
Java compiler:
javac -classpath somelib.jar;target\classes -sourcepath src -d target\classes src\com\acme\prj1\*.java
JContractS config:
java -classpath jcontracts.jar;log4j.jar;somelib.jar;target\classes net.sf.jcontracts.icontract.Tool -menabled-contracts -otarget\config-src\@p\@f.java -ktarget\repo-src\@p src\*.java
Java compiler config:
javac -classpath somelib.jar;target\config-classes -sourcepath target\config-src -d target\config-classes target\config-src\com\acme\prj1\*.java
Java compiler repo:
javac -classpath target\repo-classes -sourcepath target\repo-src -d target\repo-classes target\repo-src\com\acme\prj1\*.java
Java compiler:
javac -classpath prj1.jar;somelib.jar;target\classes -sourcepath src -d target\classes src\com\acme\prj2\*.java
JContractS config:
java -classpath jcontract.jar;log4j.jar;prj1-config.jar;prj1-repo.jar;somelib.jar;target\classes net.sf.jcontracts.icontract.Tool -mconfig -otarget\config-src\@p\@f.java -ktarget\repo-src\@p src\*.java
Java compiler config:
javac -classpath prj1-config.jar;somelib.jar;target\config-classes -sourcepath target\config-src -d target\config-classes target\config-src\com\acme\prj2\*.java
Java compiler repo:
javac -classpath prj1-repo.jar;target\repo-classes -sourcepath target\repo-src -d target\repo-classes target\repo-src\com\acme\prj2\*.java