1

私は maven-jetty-plugin を使用しています。Jetty は統合前テスト段階で開始されます。起動しますが、次のエラーが発生します。

java.lang.NoClassDefFoundError: org/spingframework/context/ApplicationContext.

spring を含むように jetty クラスパスを解決するにはどうすればよいですか?

[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>

4

1 に答える 1

0

次の依存関係が必要になります。

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>3.0.5.RELEASE</version>
        </dependency>

NoClassDefFoundError を解決するために。ただし、Springframework の基本的なものを使用するために、後でさらに依存関係 (spring-beans、spring-core、spring-context-support など) が必要になる可能性が高くなります。

さらに、JarvanaまたはFindJarを使用して、依存関係として追加する必要があるクラスを含むアーティファクトを特定できます。

于 2012-06-08T13:20:13.633 に答える