Weird NoClassDef-s with Eclipse Jetty's Maven

2020-06-05 02:32发布

I am using an embedded Jetty via the Eclipse Jetty Maven plugin (9.1.0.M0).

I have the following plugin configuration in my 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>

I keep getting the following exception when Jetty is shutting down:

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

I have tried adding jetty-util as a dependency of the plugin, (and, also -- the project). This didn't help and it's driving me mad. While the build is indeed passing, I really can't stand seeing these errors when Jetty is shutting down at the end of my Maven build.

Please, advise! Many thanks in advance!

6条回答
叼着烟拽天下
2楼-- · 2020-06-05 02:57

I had the same problem with maven-jetty-plugin version 8.1.14.v20131031 when running integration tests in 'verify' phase.

Two dependencies were required (note the exact versions as in 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>

finally I used this maven-jetty-plugin configuration:

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

During actual "jetty-maven-plugin:8.1.14.v20131031:stop (stop-jetty)" phase, there were some errors (namely complaints about missing stopPort & stopKey) reported by the plugin itself, which were causing

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

查看更多
做自己的国王
3楼-- · 2020-06-05 03:05

You should not be using the "run" goal with an execution binding. Instead, you should be using the "start" goal. See the documentation here: http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html#jetty-start-goal

The difference is that the "run" goal will run a fresh build up until the "test-compile" phase. The "start" goal does not invoke a parallel build and simply runs at whatever phase it is bound to.

Jan

查看更多
劫难
4楼-- · 2020-06-05 03:05

I solved it adding the configurations in the docs: 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>
查看更多
时光不老,我们不散
5楼-- · 2020-06-05 03:08

I would suggest you use a release version, e.g. 9.0.5.v20130815, instead of milestone ( which is still in development ) as you're using right now 9.1.0.M0

查看更多
Evening l夕情丶
6楼-- · 2020-06-05 03:12

Just try to add <stopWait>10</stopWait> to plugin configuration.

Full configuration:

<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>
查看更多
劳资没心,怎么记你
7楼-- · 2020-06-05 03:12

I've had to struggle a lot with this, before finding this answer: https://stackoverflow.com/a/22856563/529286. Basically, it works like Risto Oikarinen says, with the addition that: - with recent Jetty releases (9.1.x), you don't need any further Jetty dependency - with the 'stop' goal attached to the 'post-integration-test' phase, you do need to invoke 'verify' or 'install' (or later goals), in order to have Jetty correctly stopped.

查看更多
登录 后发表回答