gpt4 book ai didi

java - 将 Cofoja 与 Wicket 一起使用(甚至仅与 Maven 一起使用)

转载 作者:行者123 更新时间:2023-12-02 08:10:19 25 4
gpt4 key购买 nike

我正在尽最大努力让 Google Cofoja 在我的 Apache Wicket 中运行使用 Maven2 的应用程序似乎是标准的。

该项目最初是使用 Leg Up 生成的选择原型(prototype)“Wicket 1.4.12、Guice 2.0、WarpPersist 2.0(快照)、Hibernate 3.5.6”。

我最近尝试过的(似乎是最接近工作的)是使用 maven 进行构建(我已经设法构建了合约类),然后尝试使用 ant 运行项目来获取进行契约(Contract)检查。 当前的问题是我不确定如何创建我的main类。我尝试将其设置为运行jetty服务器的类,但我得到的类不是发现异常。

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

同样,即使我确实让这个解决方案发挥作用,这也远非将契约(Contract)检查作为 Maven 构建的一部分进行的理想解决方案。

现在,我目前拥有的:

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);
}
}
}

如果你知道如何解决我当前的 Ant 问题,或者更好的是,知道如何一起废弃 Ant 黑客,那将是非常令人兴奋的(:

更新 1

从代码中删除了 -,因为这很糟糕(感谢@Martijn Dashorst)。遗憾的是,这并没有解决问题。

最佳答案

请勿在 Artifact 和组 ID 中使用-。它们是无效的 Java 标识符字符。该脚本使用 groupId 和 artifactId 在您的项目中生成包名称。

关于java - 将 Cofoja 与 Wicket 一起使用(甚至仅与 Maven 一起使用),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7564480/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com