Enabling and Running C4J Applications

For your java projects to compile, you must have the c4j.jar library in your classpath. We will discuss the best way how to add the library below.

In order to enable contract verification during the runtime of your application, you need to supply a -javaagent VM argument and enable assertions. You could do this in the command-line like:

java -cp <your_classpath> -javaagent:$ECLIPSE_HOME/plugins/net.sourceforge.c4jplugin.runtime/c4j.jar -ea <your_main_class>

where $ECLIPSE_HOME stands for your Eclipse installation path, assuming that you installed the net.sourceforge.c4jplugin.runtime plug-in in the standard Eclipse plug-ins folder. But this is not the preferred way, since Eclipse uses run configurations to run your applications.

Note: The plug-in net.sourceforge.c4jplugin can automatically perform the following steps for you. See the C4J Plug-in User Guide for more information.

The Eclipse Way for Java Projects

To add c4j.jar to your build path and enable C4J for a specific run configuration of your java project, follow these two steps:

  1. Add the c4j.jar library to the build path of your project



  2. Add the following VM arguments to your run configuration


The Eclipse Way for Plug-in Projects

Because the c4j.jar library is contained in the plugin net.sourceforge.c4jplugin.runtime, you can add the plug-in to the list of required plug-ins in your MANIFEST.MF file. Then you need to add the VM arguments as above:

  1. Add plug-in dependency



  2. Add VM arguments to your run configuration
    You can use the same arguments as in step 2 above for Java projects.