標準のように Maven2 を使用するApache WicketアプリケーションでGoogle Cofoja を実行するために、私は最善を尽くしています。
このプロジェクトは、当初、アーキタイプ「Wicket 1.4.12、Guice 2.0、WarpPersist 2.0 (スナップショット)、Hibernate 3.5.6」が選択されたLeg Upを使用して生成されました。
私が最近試した (そして最も動作に近いように思われる) のは、maven (コントラクト クラスをビルドすることができた) を使用してビルドし、ant を使用してプロジェクトを実行して、コントラクト チェックを取得しようとすることです。起こる。最新の問題は、何をメインクラスにすればよいかわからないことです。jetty サーバーを実行するクラスにしようとしましたが、class not found 例外が発生します。
J:\adminconsole>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
同様に、このソリューションが機能したとしても、コントラクト チェックを maven build の一部として実行するという理想的なソリューションにはほど遠いものです。
今、私が現在持っているもの:
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.myproject</groupId>
<artifactId>adminconsole</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<properties>
<jdk.version>1.5</jdk.version>
<slf4j.version>1.5.11</slf4j.version>
<wicket.version>1.4.12</wicket.version>
<jetty.version>6.1.25</jetty.version>
<cofoja.version>1.0</cofoja.version>
<asm.version>3.3.1</asm.version>
</properties>
<name>Admin Console New</name>
<!--
<repositories>
<repository>
<id>jboss</id>
<name>JBoss Repository</name>
<url>https://repository.jboss.org/nexus/content/groups/public/</url>
</repository>
</repositories>
-->
<build>
<finalName>fsrpadmin</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/java</directory>
<includes>
<include>**</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
<testResource>
<directory>src/test/resources</directory>
<includes>
<include>**</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>
<plugins>
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addClasspath>true</addClasspath>
<mainClass>com.mycompany.myproject.adminconsole.Start</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>${jetty.version}</version>
<configuration>
<scanIntervalSeconds>5</scanIntervalSeconds>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.5</version>
<configuration>
<targetJdk>${jdk.version}</targetJdk>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<configuration>
<xmlOutput>true</xmlOutput>
<effort>Max</effort>
<threshold>Low</threshold>
</configuration>
<version>2.3.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
</plugin>
<!-- Run annotation processors on src/main/java sources -->
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<outputDirectory>target\classes</outputDirectory>
<processors>
<processor>com.google.java.contract.core.apt.AnnotationProcessor</processor>
</processors>
</configuration>
</execution>
</executions>
</plugin>
<!-- Run annotation processors on src/test/java sources -->
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<executions>
<execution>
<id>process-test</id>
<goals>
<goal>process-test</goal>
</goals>
<phase>generate-test-sources</phase>
<configuration>
<outputDirectory>target\classes</outputDirectory>
<processors>
<processor>com.google.java.contract.core.apt.AnnotationProcessor</processor>
</processors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<!-- WICKET DEPENDENCIES -->
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket</artifactId>
<version>${wicket.version}</version>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-guice</artifactId>
<version>${wicket.version}</version>
</dependency>
<!-- LOGGING DEPENDENCIES - LOG4J -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.10</version>
<scope>runtime</scope>
</dependency>
<!-- You will need to install this yourself from http://warp-persist.googlecode.com/svn/trunk/warp-persist/dist/ -->
<dependency>
<groupId>com.wideplay.warp</groupId>
<artifactId>warp-persist</artifactId>
<version>2.0-20090214</version>
</dependency>
<!-- Cofojo - Contracts for Java LOCALLY INSTALLED from http://code.google.com/p/cofoja/downloads/list -->
<dependency>
<groupId>com.google</groupId>
<artifactId>cofoja</artifactId>
<version>${cofoja.version}</version>
</dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm-all</artifactId>
<version>${asm.version}</version>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.5.6-Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.5.6-Final</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.8.0.GA</version>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
<version>${jetty.version}</version>
<scope>provided</scope>
</dependency>
<!-- Other -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="adminconsole-run" default="package" basedir=".">
<!-- ====================================================================== -->
<!-- Build environment properties -->
<!-- ====================================================================== -->
<property file="${user.home}/.m2/maven.properties"/>
<property file="maven-build.properties"/>
<!-- ====================================================================== -->
<!-- Run Contracts target -->
<!-- ====================================================================== -->
<target name="run">
<java jar="${maven.build.dir}/${maven.build.finalName}.war" fork="true">
<jvmarg value="-javaagent:lib/cofoja/cofoja-1.0-r138.jar"/>
</java>
</target>
</project>
maven-build.properties
maven.build.finalName=fsrpadmin
maven.build.dir=target
com/mycompany/myproject/adminconsole/Start.java
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(">>> 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);
}
}
}
あなたが私の現在のアリの問題を解決する方法を知っているなら、またはさらに良いことに、アリのハックをすべて一緒に廃棄する方法のアイデアを持っているなら、それは非常にエキサイティングです (:
更新 1
悪いので、コードから 's を削除-
しました (@Martijn Dashorst に感謝)。残念ながら、これで問題は解決しませんでした。