4

我通过 Eclipse Jetty Maven 插件 (9.1.0.M0) 使用嵌入式 Jetty。

我的插件配置如下pom.xml

                <plugin>
                    <groupId>org.eclipse.jetty</groupId>
                    <artifactId>jetty-maven-plugin</artifactId>
                    <version>${version.jetty}</version>

                    <configuration>
                        <scanIntervalSeconds>10</scanIntervalSeconds>
                        <daemon>true</daemon>

                        <webApp>
                            <contextPath>/</contextPath>
                            <descriptor>${basedir}/src/test/webapp/WEB-INF/web.xml</descriptor>
                        </webApp>

                        <httpConnector>
                            <port>48080</port>
                        </httpConnector>

                        <stopPort>19081</stopPort>
                        <stopKey>53AS9DS1FD8E3WEFEW9GR1ER8G2ER0WE31</stopKey>
                    </configuration>

                    <executions>
                        <execution>
                            <id>jetty-start</id>

                            <phase>test-compile</phase>
                            <goals>
                                <goal>run</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>jetty-stop</id>

                            <phase>test</phase>
                            <goals>
                                <goal>stop</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

Jetty 关闭时,我不断收到以下异常:

2013-09-27 04:51:08.309:WARN:oejuc.AbstractLifeCycle:Thread-68: FAILED WebSocketClient@873794597{FAILED,8<=8<=200,i=8,q=0}: java.lang.NoClassDefFoundError: org/eclipse/jetty/util/thread/QueuedThreadPool$1
java.lang.NoClassDefFoundError: org/eclipse/jetty/util/thread/QueuedThreadPool$1
    at org.eclipse.jetty.util.thread.QueuedThreadPool.doStop(QueuedThreadPool.java:121)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:90)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.stop(ContainerLifeCycle.java:129)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStop(ContainerLifeCycle.java:148)
    at org.eclipse.jetty.websocket.client.WebSocketClient.doStop(WebSocketClient.java:263)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:90)
    at org.eclipse.jetty.util.thread.ShutdownThread.run(ShutdownThread.java:133)
Caused by: 
java.lang.ClassNotFoundException: org.eclipse.jetty.util.thread.QueuedThreadPool$1
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:244)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:230)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.doStop(QueuedThreadPool.java:121)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:90)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.stop(ContainerLifeCycle.java:129)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStop(ContainerLifeCycle.java:148)
    at org.eclipse.jetty.websocket.client.WebSocketClient.doStop(WebSocketClient.java:263)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:90)
    at org.eclipse.jetty.util.thread.ShutdownThread.run(ShutdownThread.java:133)
2013-09-27 04:51:08.310:WARN:oejuc.AbstractLifeCycle:Thread-68: FAILED org.eclipse.jetty.websocket.client.WebSocketClient@34150c25: java.lang.NoClassDefFoundError: org/eclipse/jetty/util/thread/QueuedThreadPool$1
java.lang.NoClassDefFoundError: org/eclipse/jetty/util/thread/QueuedThreadPool$1
    at org.eclipse.jetty.util.thread.QueuedThreadPool.doStop(QueuedThreadPool.java:121)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:90)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.stop(ContainerLifeCycle.java:129)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStop(ContainerLifeCycle.java:148)
    at org.eclipse.jetty.websocket.client.WebSocketClient.doStop(WebSocketClient.java:263)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:90)
    at org.eclipse.jetty.util.thread.ShutdownThread.run(ShutdownThread.java:133)
Caused by: 
java.lang.ClassNotFoundException: org.eclipse.jetty.util.thread.QueuedThreadPool$1
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:244)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:230)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.doStop(QueuedThreadPool.java:121)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:90)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.stop(ContainerLifeCycle.java:129)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStop(ContainerLifeCycle.java:148)
    at org.eclipse.jetty.websocket.client.WebSocketClient.doStop(WebSocketClient.java:263)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:90)
    at org.eclipse.jetty.util.thread.ShutdownThread.run(ShutdownThread.java:133)
Exception in thread "Thread-68" java.lang.NoClassDefFoundError: org/eclipse/jetty/util/thread/QueuedThreadPool$1
    at org.eclipse.jetty.util.thread.QueuedThreadPool.doStop(QueuedThreadPool.java:121)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:90)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.stop(ContainerLifeCycle.java:129)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStop(ContainerLifeCycle.java:148)
    at org.eclipse.jetty.websocket.client.WebSocketClient.doStop(WebSocketClient.java:263)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:90)
    at org.eclipse.jetty.util.thread.ShutdownThread.run(ShutdownThread.java:133)
Caused by: java.lang.ClassNotFoundException: org.eclipse.jetty.util.thread.QueuedThreadPool$1
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:244)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:230)
    ... 7 more

我已经尝试添加jetty-util作为插件的依赖项,(以及 - 项目)。这没有帮助,它让我发疯。虽然构建确实通过了,但当 Jetty 在我的 Maven 构建结束时关闭时,我真的无法忍受看到这些错误。

请指教!提前谢谢了!

4

6 回答 6

2

我建议您使用发布版本,例如9.0.5.v20130815,而不是您现在使用的里程碑(仍在开发中)9.1.0.M0

于 2013-09-27T07:37:45.163 回答
2

只需尝试添加<stopWait>10</stopWait>到插件配置。

完整配置:

<plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>9.1.4.v20140401</version>

    <configuration>
        <stopPort>8005</stopPort>
        <stopKey>STOP</stopKey>
        <stopWait>10</stopWait>
    </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>
于 2014-04-16T06:52:26.537 回答
2

您不应该将“运行”目标与执行绑定一起使用。相反,您应该使用“开始”目标。请参阅此处的文档:http: //www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html#jetty-start-goal

不同之处在于“运行”目标将运行一个新的构建,直到“测试-编译”阶段。“开始”目标不会调用并行构建,而只是在它绑定到的任何阶段运行。

于 2014-07-02T04:35:51.247 回答
1

在“验证”阶段运行集成测试时,我遇到了与 maven-jetty-plugin 版本 8.1.14.v20131031 相同的问题。

需要两个依赖项(注意 maven-jetty-plugin 中的确切版本):

    <dependency>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-jsp</artifactId>
        <version>8.1.14.v20131031</version>
    </dependency>
    <dependency>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-util</artifactId>
        <version>8.1.14.v20131031</version>
    </dependency>

最后我使用了这个 maven-jetty-plugin 配置:

<plugin>
<!-- jetty-maven-plugin must be outside pluginManagement, otherwise it does not run properly during 'verify' -->
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>8.1.14.v20131031</version>
    <configuration>
        <stopPort>9966</stopPort>
        <stopKey>PARENT</stopKey>
    </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>

在实际的“jetty-maven-plugin:8.1.14.v20131031:stop (stop-jetty)”阶段,插件本身报告了一些错误(即抱怨缺少 stopPort 和 stopKey),这导致

java.lang.ClassNotFoundException: org.eclipse.jetty.util.thread.QueuedThreadPool$1

于 2013-12-11T09:20:39.873 回答
1

在找到这个答案之前,我不得不为此苦苦挣扎:https ://stackoverflow.com/a/22856563/529286 。基本上,它就像 Risto Oikarinen 所说的那样工作,此外: - 对于最近的 Jetty 版本 (9.1.x),您不需要任何进一步的 Jetty 依赖 - 将“停止”目标附加到“集成后测试” ' 阶段,您确实需要调用 'verify' 或 'install' (或以后的目标),以使 Jetty 正确停止。

于 2014-04-04T07:45:29.083 回答
0

我解决了它在文档中添加配置:http: //www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html#jetty-stop-goal

       <plugin>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>9.1.4.v20140401</version>
            <configuration>
                <contextPath>/</contextPath>
                <scanIntervalSeconds>0</scanIntervalSeconds>
                <stopPort>9966</stopPort>
                <stopKey>foo</stopKey>
                <stopWait>10</stopWait>
            </configuration>
            <executions>
                <execution>
                    <id>start-jetty</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <daemon>true</daemon>
                    </configuration>
                </execution>
                <execution>
                    <id>stop-jetty</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
于 2014-04-10T12:40:42.447 回答