10

我正在使用 Maven、Selenium 和 Jetty 运行集成测试。测试执行正常,但是当服务器关闭时,Jetty 服务器会抛出一个java.lang.ClassNotFoundException: org.codehaus.groovy.runtime.dgm$371. 这是完整的堆栈跟踪:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.main.SeleniumHelloWorldExampleIT
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 13.479 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- selenium-maven-plugin:2.3:stop-server (stop-selenium) @ MySampleWebApp ---
Stopping Selenium server...
00:28:55,976 INFO  [org.openqa.jetty.util.Credential] Checking Resource aliases
00:28:55.983 INFO - Command request: shutDownSeleniumServer[, ] on session null
00:28:55.989 INFO - Shutdown command received
00:28:55.992 INFO - Got result: OK on session null
00:28:55.994 INFO - initiating shutdown
Stop request sent
[INFO] 
[INFO] --- maven-jetty-plugin:6.1.26:stop (stop-jetty) @ MySampleWebApp ---
[INFO] 
[INFO] --- maven-failsafe-plugin:2.9:verify (verify) @ MySampleWebApp ---
[INFO] Stopping server 0
[INFO] Stopped SelectChannelConnector@0.0.0.0:8080
[INFO] Failsafe report directory: D:\projects\mvn-ckbk-samples\ch-2\test-auto\MySampleWebApp\target\failsafe-reports
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:06.833s
[INFO] Finished at: Sat Nov 09 00:28:56 VET 2013
[INFO] Final Memory: 15M/38M
[INFO] ------------------------------------------------------------------------
[INFO] Shutdown hook executing
java.lang.ClassNotFoundException: org.codehaus.groovy.runtime.dgm$371
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:235)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227)
    at org.codehaus.groovy.reflection.GeneratedMetaMethod$Proxy.createProxy(GeneratedMetaMethod.java:86)
    at org.codehaus.groovy.reflection.GeneratedMetaMethod$Proxy.proxy(GeneratedMetaMethod.java:79)
    at org.codehaus.groovy.reflection.GeneratedMetaMethod$Proxy.isValidMethod(GeneratedMetaMethod.java:65)
    at groovy.lang.MetaClassImpl.chooseMethodInternal(MetaClassImpl.java:2808)
    at groovy.lang.MetaClassImpl.chooseMethod(MetaClassImpl.java:2800)
    at groovy.lang.MetaClassImpl.getMethodWithCachingInternal(MetaClassImpl.java:1181)
    at groovy.lang.MetaClassImpl.createPojoCallSite(MetaClassImpl.java:3001)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.createPojoSite(CallSiteArray.java:114)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallSite(CallSiteArray.java:148)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
    at org.codehaus.gmaven.mojo.support.ProcessLauncher$_launch_closure1.doCall(ProcessLauncher.groovy:65)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:273)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:149)
    at org.codehaus.gmaven.mojo.support.ProcessLauncher$_launch_closure1.doCall(ProcessLauncher.groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:273)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)
    at groovy.lang.Closure.call(Closure.java:276)
    at groovy.lang.Closure.call(Closure.java:271)
    at groovy.lang.Closure.run(Closure.java:354)
    at java.lang.Thread.run(Thread.java:724)
Exception in thread "Selenium Server Runner" org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.ClassNotFoundException: org.codehaus.groovy.runtime.dgm$371
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:95)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:273)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)
    at groovy.lang.Closure.call(Closure.java:276)
    at groovy.lang.Closure.call(Closure.java:271)
    at groovy.lang.Closure.run(Closure.java:354)
    at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.ClassNotFoundException: org.codehaus.groovy.runtime.dgm$371
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:235)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227)
    at org.codehaus.groovy.reflection.GeneratedMetaMethod$Proxy.createProxy(GeneratedMetaMethod.java:86)
    at org.codehaus.groovy.reflection.GeneratedMetaMethod$Proxy.proxy(GeneratedMetaMethod.java:79)
    at org.codehaus.groovy.reflection.GeneratedMetaMethod$Proxy.isValidMethod(GeneratedMetaMethod.java:65)
    at groovy.lang.MetaClassImpl.chooseMethodInternal(MetaClassImpl.java:2808)
    at groovy.lang.MetaClassImpl.chooseMethod(MetaClassImpl.java:2800)
    at groovy.lang.MetaClassImpl.getMethodWithCachingInternal(MetaClassImpl.java:1181)
    at groovy.lang.MetaClassImpl.createPojoCallSite(MetaClassImpl.java:3001)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.createPojoSite(CallSiteArray.java:114)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallSite(CallSiteArray.java:148)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
    at org.codehaus.gmaven.mojo.support.ProcessLauncher$_launch_closure1.doCall(ProcessLauncher.groovy:65)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:273)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:149)
    at org.codehaus.gmaven.mojo.support.ProcessLauncher$_launch_closure1.doCall(ProcessLauncher.groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
    ... 7 more
[INFO] Shutdown hook complete

Process finished with exit code 0

知道为什么会这样吗?

我正在使用的 POM:

<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>MySampleWebApp</groupId>
    <artifactId>MySampleWebApp</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>MySampleWebApp Maven Webapp</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <scope>test</scope>
            <version>2.37.1</version>
        </dependency>

       <dependency>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jsp-2.1</artifactId>
            <version>6.0.0</version>
       </dependency>
    </dependencies>

    <build>
        <finalName>MySampleWebApp</finalName>
        <plugins>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>selenium-maven-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <id>start-selenium</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start-server</goal>
                        </goals>
                        <configuration>
                            <background>true</background>
                        </configuration>
                    </execution>
                    <execution>
                        <id>stop-selenium</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop-server</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
                <version>6.1.26</version>
                <configuration>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <stopKey>stop</stopKey>
                    <stopPort>8005</stopPort>
                </configuration>
                <executions>
                    <execution>
                        <id>start-jetty</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <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>

            <!-- Failsafe for integration testing -->
            <!-- This ensures that post-integration tests are run even if testing fails -->
            <!-- Integration tests are *IT.java by default -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.9</version>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>verify</id>
                        <goals>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>
4

3 回答 3

2

尝试在码头配置中添加 stopWait :

<configuration>
  <scanIntervalSeconds>10</scanIntervalSeconds>
  <stopKey>stop</stopKey>
  <stopPort>8005</stopPort>

  <stopWait>5</stopWait>

</configuration>

这可以确保码头在执行下一个 Maven 目标之前停止,重要的是在构建完成之前停止。

在这种情况下,当 Maven 构建完成时 Jetty 尝试关闭,您将看到这个 ClassNotFoundError。

另请参阅http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html#jetty-stop-goal

于 2014-01-25T07:15:44.517 回答
2

看起来缺少 groovy 运行时依赖项。请参考http://docs.codehaus.org/display/GMAVEN/Groovy+Runtime

于 2013-10-31T05:39:47.913 回答
1

我解决了这个问题,添加了这个依赖

        <dependency>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jsp-2.1</artifactId>
            <version>6.0.0</version>
          </dependency>
于 2013-12-10T09:23:21.090 回答