title: Using Cofoja with Wicket (or even with just Maven)
body: <p>I am trying my darnedest to get Google Cofoja to run in my <a href="http://wicket.apache.org/" rel="nofollow">Apache Wicket</a> application which uses Maven2 as seems to be standard.</p>
  
  <p>The project was initially generated using <a href="http://www.jweekend.com/dev/LegUp" rel="nofollow">Leg Up</a> with the Archetype "Wicket 1.4.12, Guice 2.0, WarpPersist 2.0 (snapshot), Hibernate 3.5.6" selected.</p>
  
  <p>What I've tried most recently (and seems to be the closest to working) is building with maven (which i've managed to make build the contract classes), and then attempting to run the project using ant to get the contract checks to happen. <strong>The most current problem is I am not sure what to make my <em>main</em> class.</strong> I've tried making it the class that runs the jetty server, but I get a class not found exception.</p>
  
  <pre><code>J:\adminconsole&gt;ant run
  Buildfile: J:\adminconsole\build.xml
  
  run:
       [java] java.lang.NoClassDefFoundError: com/mycompany/myproject/adminconsole/Start
       [java] Caused by: java.lang.ClassNotFoundException: com.mycompany.myproject.adminconsole.Start
       [java]     at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
       [java]     at java.security.AccessController.doPrivileged(Native Method)
       [java]     at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
       [java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
       [java]     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
  
       [java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
       [java] Could not find the main class: com.mycompany.myproject.adminconsole.Start. Program will exit.
       [java] Exception in thread "main"
       [java] Java Result: 1
  
  BUILD SUCCESSFUL
  Total time: 2 seconds
  </code></pre>
  
  <p>As well, even if I did get this solution working, this is far from the ideal solution of <strong>having the contract checks happen as part of the maven build</strong>.</p>
  
  <p>Now, what I have currently:</p>
  
  <h2>pom.xml</h2>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;com.mycompany.myproject&lt;/groupId&gt;
      &lt;artifactId&gt;adminconsole&lt;/artifactId&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
      &lt;properties&gt;
          &lt;jdk.version&gt;1.5&lt;/jdk.version&gt;
  
          &lt;slf4j.version&gt;1.5.11&lt;/slf4j.version&gt;
          &lt;wicket.version&gt;1.4.12&lt;/wicket.version&gt;
          &lt;jetty.version&gt;6.1.25&lt;/jetty.version&gt;
          &lt;cofoja.version&gt;1.0&lt;/cofoja.version&gt;
          &lt;asm.version&gt;3.3.1&lt;/asm.version&gt;
      &lt;/properties&gt;
      &lt;name&gt;Admin Console New&lt;/name&gt;
  &lt;!--
      &lt;repositories&gt;
          &lt;repository&gt;
              &lt;id&gt;jboss&lt;/id&gt;
              &lt;name&gt;JBoss Repository&lt;/name&gt;
              &lt;url&gt;https://repository.jboss.org/nexus/content/groups/public/&lt;/url&gt;
          &lt;/repository&gt;
      &lt;/repositories&gt;
  --&gt;
      &lt;build&gt;
          &lt;finalName&gt;fsrpadmin&lt;/finalName&gt;
          &lt;resources&gt;
              &lt;resource&gt;
                  &lt;directory&gt;src/main/resources&lt;/directory&gt;
                  &lt;includes&gt;
                      &lt;include&gt;**&lt;/include&gt;
                  &lt;/includes&gt;
                  &lt;excludes&gt;
                      &lt;exclude&gt;**/*.java&lt;/exclude&gt;
                  &lt;/excludes&gt;
              &lt;/resource&gt;
              &lt;resource&gt;
                  &lt;directory&gt;src/main/java&lt;/directory&gt;
                  &lt;includes&gt;
                      &lt;include&gt;**&lt;/include&gt;
                  &lt;/includes&gt;
                  &lt;excludes&gt;
                      &lt;exclude&gt;**/*.java&lt;/exclude&gt;
                  &lt;/excludes&gt;
              &lt;/resource&gt;
          &lt;/resources&gt;
          &lt;testResources&gt;
              &lt;testResource&gt;
                  &lt;directory&gt;src/test/java&lt;/directory&gt;
                  &lt;includes&gt;
                      &lt;include&gt;**&lt;/include&gt;
                  &lt;/includes&gt;
                  &lt;excludes&gt;
                      &lt;exclude&gt;**/*.java&lt;/exclude&gt;
                  &lt;/excludes&gt;
              &lt;/testResource&gt;
              &lt;testResource&gt;
                  &lt;directory&gt;src/test/resources&lt;/directory&gt;
                  &lt;includes&gt;
                      &lt;include&gt;**&lt;/include&gt;
                  &lt;/includes&gt;
                  &lt;excludes&gt;
                      &lt;exclude&gt;**/*.java&lt;/exclude&gt;
                  &lt;/excludes&gt;
              &lt;/testResource&gt;
          &lt;/testResources&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;inherited&gt;true&lt;/inherited&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;${jdk.version}&lt;/source&gt;
                      &lt;target&gt;${jdk.version}&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
                  &lt;configuration&gt;
                      &lt;archive&gt;
                          &lt;manifest&gt;
                              &lt;addDefaultImplementationEntries&gt;true&lt;/addDefaultImplementationEntries&gt;
                              &lt;addClasspath&gt;true&lt;/addClasspath&gt;
                              &lt;mainClass&gt;com.mycompany.myproject.adminconsole.Start&lt;/mainClass&gt;
                          &lt;/manifest&gt;
                      &lt;/archive&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.mortbay.jetty&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-jetty-plugin&lt;/artifactId&gt;
                  &lt;version&gt;${jetty.version}&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;scanIntervalSeconds&gt;5&lt;/scanIntervalSeconds&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-pmd-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.5&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;targetJdk&gt;${jdk.version}&lt;/targetJdk&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
                  &lt;artifactId&gt;findbugs-maven-plugin&lt;/artifactId&gt;
                  &lt;configuration&gt;
                      &lt;xmlOutput&gt;true&lt;/xmlOutput&gt;
                      &lt;effort&gt;Max&lt;/effort&gt;
                      &lt;threshold&gt;Low&lt;/threshold&gt;
                  &lt;/configuration&gt;
                  &lt;version&gt;2.3.2&lt;/version&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-javadoc-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.8&lt;/version&gt;
              &lt;/plugin&gt;
  
              &lt;!-- Run annotation processors on src/main/java sources --&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.bsc.maven&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-processor-plugin&lt;/artifactId&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;id&gt;process&lt;/id&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;process&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;phase&gt;generate-sources&lt;/phase&gt;
                          &lt;configuration&gt;
                              &lt;outputDirectory&gt;target\classes&lt;/outputDirectory&gt;
                              &lt;processors&gt;
                                  &lt;processor&gt;com.google.java.contract.core.apt.AnnotationProcessor&lt;/processor&gt;
                              &lt;/processors&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
              &lt;!-- Run annotation processors on src/test/java sources --&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.bsc.maven&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-processor-plugin&lt;/artifactId&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;id&gt;process-test&lt;/id&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;process-test&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;phase&gt;generate-test-sources&lt;/phase&gt;
                          &lt;configuration&gt;
                              &lt;outputDirectory&gt;target\classes&lt;/outputDirectory&gt;
                              &lt;processors&gt;
                                  &lt;processor&gt;com.google.java.contract.core.apt.AnnotationProcessor&lt;/processor&gt;
                              &lt;/processors&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
  
          &lt;/plugins&gt;
      &lt;/build&gt;
  
      &lt;dependencies&gt;
          &lt;!--  WICKET DEPENDENCIES --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.wicket&lt;/groupId&gt;
              &lt;artifactId&gt;wicket&lt;/artifactId&gt;
              &lt;version&gt;${wicket.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.wicket&lt;/groupId&gt;
              &lt;artifactId&gt;wicket-guice&lt;/artifactId&gt;
              &lt;version&gt;${wicket.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- LOGGING DEPENDENCIES - LOG4J --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
              &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
              &lt;version&gt;${slf4j.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
              &lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt;
              &lt;version&gt;${slf4j.version}&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;log4j&lt;/groupId&gt;
              &lt;artifactId&gt;log4j&lt;/artifactId&gt;
              &lt;version&gt;1.2.14&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;hsqldb&lt;/groupId&gt;
              &lt;artifactId&gt;hsqldb&lt;/artifactId&gt;
              &lt;version&gt;1.8.0.10&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;!-- You will need to install this yourself from http://warp-persist.googlecode.com/svn/trunk/warp-persist/dist/ --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.wideplay.warp&lt;/groupId&gt;
              &lt;artifactId&gt;warp-persist&lt;/artifactId&gt;
              &lt;version&gt;2.0-20090214&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- Cofojo - Contracts for Java LOCALLY INSTALLED from http://code.google.com/p/cofoja/downloads/list --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.google&lt;/groupId&gt;
              &lt;artifactId&gt;cofoja&lt;/artifactId&gt;
              &lt;version&gt;${cofoja.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;asm&lt;/groupId&gt;
              &lt;artifactId&gt;asm-all&lt;/artifactId&gt;
              &lt;version&gt;${asm.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- Hibernate --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
              &lt;version&gt;3.5.6-Final&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-annotations&lt;/artifactId&gt;
              &lt;version&gt;3.5.6-Final&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javassist&lt;/groupId&gt;
              &lt;artifactId&gt;javassist&lt;/artifactId&gt;
              &lt;version&gt;3.8.0.GA&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.mortbay.jetty&lt;/groupId&gt;
              &lt;artifactId&gt;jetty&lt;/artifactId&gt;
              &lt;version&gt;${jetty.version}&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;!-- Other --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;version&gt;4.8.1&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.mockito&lt;/groupId&gt;
              &lt;artifactId&gt;mockito-core&lt;/artifactId&gt;
              &lt;version&gt;1.8.2&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  &lt;/project&gt;
  </code></pre>
  
  <h2>build.xml</h2>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project name="adminconsole-run" default="package" basedir="."&gt;
  
  &lt;!-- ====================================================================== --&gt;
  &lt;!-- Build environment properties                                           --&gt;
  &lt;!-- ====================================================================== --&gt;
  
  &lt;property file="${user.home}/.m2/maven.properties"/&gt;
  &lt;property file="maven-build.properties"/&gt;
  
  &lt;!-- ====================================================================== --&gt;
  &lt;!-- Run Contracts target                                                   --&gt;
  &lt;!-- ====================================================================== --&gt;
  &lt;target name="run"&gt;
      &lt;java jar="${maven.build.dir}/${maven.build.finalName}.war" fork="true"&gt;
          &lt;jvmarg value="-javaagent:lib/cofoja/cofoja-1.0-r138.jar"/&gt;
      &lt;/java&gt;
  &lt;/target&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <h2>maven-build.properties</h2>
  
  <pre><code>maven.build.finalName=fsrpadmin
  maven.build.dir=target
  </code></pre>
  
  <h2>com/mycompany/myproject/adminconsole/Start.java</h2>
  
  <pre><code>package com.marsh.fsrp.adminconsole;
  
  import org.mortbay.jetty.Connector;
  import org.mortbay.jetty.Server;
  import org.mortbay.jetty.bio.SocketConnector;
  import org.mortbay.jetty.webapp.WebAppContext;
  
  public class Start {
  
      public static void main(String[] args) throws Exception {
          Server server = new Server();
          SocketConnector connector = new SocketConnector();
          connector.setPort(8080);
          server.setConnectors(new Connector[] { connector });
  
          WebAppContext bb = new WebAppContext();
          bb.setServer(server);
          bb.setContextPath("/");
          bb.setWar("src/main/webapp");
  
  
          // START JMX SERVER
          // MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
          // MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
          // server.getContainer().addEventListener(mBeanContainer);
          // mBeanContainer.start();
  
          server.addHandler(bb);
  
          try {
              System.out.println("&gt;&gt;&gt; STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
              server.start();
              while (System.in.available() == 0) {
                  Thread.sleep(5000);
              }
              server.stop();
              server.join();
          } catch (Exception e) {
              e.printStackTrace();
              System.exit(100);
          }
      }
  }
  </code></pre>
  
  <p>If you know how to fix my current ant problem, or even better, have an idea of how to scrap the ant-hack all together, that would be super exciting (:</p>
  
  <h2>Update 1</h2>
  
  <p>Removed <code>-</code>'s from code as that is bad (thanks @Martijn Dashorst). Sadly, this didn't fix the problem.</p>