我通过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构建结束时关闭时,我真的无法忍受看到这些错误。
请指教!非常感谢提前!
答案 0 :(得分:2)
我建议您使用发布版本,例如9.0.5.v20130815
,而不是里程碑(现在仍在开发中),因为您现在正在使用9.1.0.M0
答案 1 :(得分: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>
答案 2 :(得分:2)
你不应该使用&#34; run&#34;目标与执行绑定。相反,你应该使用&#34; start&#34;目标。请参阅此处的文档:http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html#jetty-start-goal
区别在于&#34;运行&#34;目标将进行新的构建,直到&#34; test-compile&#34;相。 &#34;开始&#34;目标不会调用并行构建,只是在它绑定的任何阶段运行。
扬
答案 3 :(得分: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&amp; stopKey的投诉),这些错误导致
java.lang.ClassNotFoundException:org.eclipse.jetty.util.thread.QueuedThreadPool $ 1
答案 4 :(得分:1)
在找到这个答案之前,我不得不为此付出很多努力:https://stackoverflow.com/a/22856563/529286。基本上,它的工作方式就像Risto Oikarinen所说的那样,增加了: - 最近的Jetty版本(9.1.x),你不需要任何进一步的Jetty依赖 - 使用&#39; stop&#39; “整合后测试”附带的目标&#39;阶段,你需要调用&#39;验证&#39;或者&#39;安装&#39; (或后来的目标),以便让Jetty正确停止。
答案 5 :(得分: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>