我正在使用maven-jetty-plugin。 Jetty在预集成测试阶段启动。它开始但是给出了这个错误:
java.lang.NoClassDefFoundError:org / spingframework / context / ApplicationContext。
如何解决jetty类路径以包含spring?
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.415s
[INFO] Finished at: Thu Jun 07 20:05:02 IST 2012
[INFO] Final Memory: 35M/208M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.mortbay.jetty:jetty-maven-plugin:8.1.4.v20120524:run (start-jetty) on project abc:
Execution start-jetty of goal org.mortbay.jetty:jetty-maven-plugin:8.1.4.v20120524:run failed: A required class was missin
g while executing org.mortbay.jetty:jetty-maven-plugin:8.1.4.v20120524:run: org/springframework/context/ApplicationContext
[ERROR] -----------------------------------------------------
[ERROR] realm = plugin>org.mortbay.jetty:jetty-maven-plugin:8.1.4.v20120524
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/root/.m2/repository/org/mortbay/jetty/jetty-maven-plugin/8.1.4.v20120524/jetty-maven-plugin-.1.4.v20
[ERROR] urls[1] = file:/root/.m2/repository/org/eclipse/jetty/jetty-util/8.1.4.v20120524/jetty-util-8.1.4.v20120524.jar
[ERROR] urls[2] = file:/root/.m2/repository/org/eclipse/jetty/jetty-webapp/8.1.4.v20120524/jetty-webapp-8.1.4.v20120524.jar
[ERROR] urls[3] = file:/root/.m2/repository/org/eclipse/jetty/jetty-xml/8.1.4.v20120524/jetty-xml-8.1.4.v20120524.jar
[ERROR] urls[4] = file:/root/.m2/repository/org/eclipse/jetty/jetty-servlet/8.1.4.v20120524/jetty-servlet-.1.4.v20120524.jar
[ERROR] urls[5] = file:/root/.m2/repository/org/eclipse/jetty/jetty-security/8.1.4.v20120524/jetty-security-8.1.4.v2
...
[ERROR] urls[37] = file:/root/.m2/repository/org/eclipse/jetty/orbit/javax.servlet.jsp.jstl/1.2.0.v201105211821javax.servlet.jsp.jstl-1.2.0.v201105211821.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import from realm ClassRealm[maven.api, parent: null]]
[ERROR]
[ERROR] -----------------------------------------------------: org.springframework.context.ApplicationContext
pom.xml的当前状态:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<properties>
<surefire-version>2.12</surefire-version>
<failsafe-version>2.12</failsafe-version>
<servlet-api-version>2.5</servlet-api-version>
<maven-compiler-plugin>2.3.2</maven-compiler-plugin>
<maven-resources-plugin>2.4.3</maven-resources-plugin>
<maven-site-plugin>2.0-beta-7</maven-site-plugin>
<maven-war-plugin>2.2</maven-war-plugin>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${servlet-api-version}</version>
<!-- provided by web container -->
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
</dependency>
</dependencies>
<build>
<testResources>
<testResource><directory>src/main/webapp/WEB-INF</directory></testResource>
<testResource><directory>src/test/resources</directory></testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin}</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>${project.build.sourceEncoding}</encoding>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven-resources-plugin}</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>${maven-site-plugin}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin}</version>
<configuration>
<webResources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>/.xml</include>
</includes>
<targetPath>WEB-INF/lib</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-version}</version>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>src/main/webapp/WEB-INF</additionalClasspathElement>
</additionalClasspathElements>
<configuration>
<includes>
<include>Test.java</include>
</includes>
<excludes>
<exclude>FunctionalTest.java</exclude>
</excludes>
</configuration>
</configuration>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<stopKey>stop</stopKey>
<stopPort>9999</stopPort>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
</dependencies>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<project>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
</dependencies>
</project>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
答案 0 :(得分:0)
您需要以下依赖项:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
为了解决NoClassDefFoundError。但是,您最有可能在以后需要进一步的依赖,例如spring-beans,spring-core,spring-context-support等,以便使用Springframework中的基本内容。