Jetty:NoClassDefFoundError

时间:2017-01-06 10:51:38

标签: java maven pom.xml maven-jetty-plugin

我有一个pom,我按照以下方式配置了jetty插件:

<plugin>
  <groupId>org.eclipse.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <version>9.4.0.v20161208</version>
     <configuration>
        <skip>${skipTests}</skip>
        <scanIntervalSeconds>10</scanIntervalSeconds>
        <stopPort>8005</stopPort>
        <stopKey>STOP</stopKey>
        <webAppSourceDirectory>${basedir}/target/${project.artifactId}-test</webAppSourceDirectory>
        <httpConnector>
          <port>45098</port>
          <idleTimeout>60000</idleTimeout>
        </httpConnector>
        <daemon>true</daemon>
      </configuration>
      <executions>
         <execution>
            <id>start-jetty</id>
            <phase>pre-integration-test</phase>
               <goals>
                  <goal>start</goal>
               </goals>
               <configuration>
                  <scanIntervalSeconds>0</scanIntervalSeconds>
               </configuration>
          </execution>
          <execution>
             <id>stop-jetty</id>
             <phase>post-integration-test</phase>
             <goals>
                <goal>stop</goal>
             </goals>
          </execution>
        </executions>
      </plugin>

但是当码头停下来时,我得到例外:

Exception in thread "Thread-4" java.lang.NoClassDefFoundError: org/eclipse/jetty/io/ManagedSelector$CloseEndPoints
at org.eclipse.jetty.io.ManagedSelector.doStop(ManagedSelector.java:135)
at org.eclipse.jetty.util.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:89)
at org.eclipse.jetty.util.component.ContainerLifeCycle.stop(ContainerLifeCycle.java:142)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStop(ContainerLifeCycle.java:160)
at org.eclipse.jetty.io.SelectorManager.doStop(SelectorManager.java:257)
at org.eclipse.jetty.util.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:89)
at org.eclipse.jetty.util.component.ContainerLifeCycle.stop(ContainerLifeCycle.java:142)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStop(ContainerLifeCycle.java:160)
at org.eclipse.jetty.client.AbstractHttpClientTransport.doStop(AbstractHttpClientTransport.java:87)
at org.eclipse.jetty.util.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:89)
at org.eclipse.jetty.util.component.ContainerLifeCycle.stop(ContainerLifeCycle.java:142)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStop(ContainerLifeCycle.java:160)
at org.eclipse.jetty.client.HttpClient.doStop(HttpClient.java:255)
at org.eclipse.jetty.util.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:89)
at org.eclipse.jetty.util.component.ContainerLifeCycle.stop(ContainerLifeCycle.java:142)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStop(ContainerLifeCycle.java:160)
at org.eclipse.jetty.websocket.client.WebSocketClient.doStop(WebSocketClient.java:379)
at org.eclipse.jetty.util.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:89)
at org.eclipse.jetty.util.component.ContainerLifeCycle.stop(ContainerLifeCycle.java:142)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStop(ContainerLifeCycle.java:160)
at org.eclipse.jetty.websocket.jsr356.ClientContainer.doStop(ClientContainer.java:214)
at org.eclipse.jetty.util.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:89)
at org.eclipse.jetty.util.thread.ShutdownThread.run(ShutdownThread.java:138)

我尝试将插件服务器lib的依赖部分添加到插件中,但它没有成功。

4 个答案:

答案 0 :(得分:1)

我认为您需要为插件添加依赖项。 ManagedSelector在以下依赖项中可用:

<dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-io</artifactId>
    <version>9.4.0.v20161208</version>
</dependency>

您可以像这样更新pom.xml

<plugin>
  <groupId>org.eclipse.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <version>9.4.0.v20161208</version>
  <dependencies>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-io</artifactId>
      <version>9.4.0.v20161208</version>
    </dependency>
  </dependencies>
  <configuration>
    <skip>${skipTests}</skip>
    <scanIntervalSeconds>10</scanIntervalSeconds>
    <stopPort>8005</stopPort>
    <stopKey>STOP</stopKey>
    <webAppSourceDirectory>${basedir}/target/${project.artifactId}-test</webAppSourceDirectory>
    <httpConnector>
      <port>45098</port>
      <idleTimeout>60000</idleTimeout>
    </httpConnector>
    <daemon>true</daemon>
  </configuration>
  <executions>
    <execution>
      <id>start-jetty</id>
      <phase>pre-integration-test</phase>
      <goals>
        <goal>start</goal>
      </goals>
      <configuration>
        <scanIntervalSeconds>0</scanIntervalSeconds>
      </configuration>
    </execution>
    <execution>
      <id>stop-jetty</id>
      <phase>post-integration-test</phase>
      <goals>
        <goal>stop</goal>
      </goals>
    </execution>
  </executions>
</plugin>

答案 1 :(得分:1)

我遇到了同样的问题,

  1. 我在我的pom.xml文件和
  2. 中包含了jetty插件
  3. 停下了修剪码头,
  4. 清理了控制台并
  5. 更新了maven项目, 然后它开始运行。
  6. pom.xml - &gt;插件已添加

    `<plugin>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <version>9.4.3.v20170317</version>
        <configuration>
          <!-- http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html -->
          <scanIntervalSeconds>3</scanIntervalSeconds>
          <!--  By Default, jetty start on port 8080
          <httpConnector>
              <port>9090</port>
          </httpConnector>
          -->
        </configuration>
      </plugin>`
    

答案 2 :(得分:0)

当我运行命令

时,我也遇到了一些问题
 mvn integration-test

输出

Downloading: http://myserver.com/repo/org/eclipse/jetty/jetty-maven-plugin/9.4.3.v20170317/jetty-maven-plugin-9.4.3.v20170317.pom
Downloaded: http://myserver.com/repo/org/eclipse/jetty/jetty-maven-plugin/9.4.3.v20170317/jetty-maven-plugin-9.4.3.v20170317.pom (6 KB at 3.4 KB/sec)
Downloading: http://myserver.com/repo/org/eclipse/jetty/jetty-maven-plugin/9.4.3.v20170317/jetty-maven-plugin-9.4.3.v20170317.jar
Downloaded: http://myserver.com/repo/org/eclipse/jetty/jetty-maven-plugin/9.4.3.v20170317/jetty-maven-plugin-9.4.3.v20170317.jar (101 KB at 35.0 KB/sec)
Downloading: http://myserver.com/repo/org/eclipse/jetty/jetty-io/9.2.20.v20161216/jetty-io-9.2.20.v20161216.pom
Downloaded: http://myserver.com/repo/org/eclipse/jetty/jetty-io/9.2.20.v20161216/jetty-io-9.2.20.v20161216.pom (3 KB at 2.3 KB/sec)
Downloading: http://myserver.com/repo/org/eclipse/jetty/jetty-io/9.4.3.v20170317/jetty-io-9.4.3.v20170317.pom
Downloaded: http://myserver.com/repo/org/eclipse/jetty/jetty-io/9.4.3.v20170317/jetty-io-9.4.3.v20170317.pom (2 KB at 1.3 KB/sec)
Downloading: http://myserver.com/repo/org/eclipse/jetty/jetty-io/9.4.3.v20170317/jetty-io-9.4.3.v20170317.jar
Downloaded: http://myserver.com/repo/org/eclipse/jetty/jetty-io/9.4.3.v20170317/jetty-io-9.4.3.v20170317.jar (128 KB at 43.2 KB/sec)

奇怪的是,有些东西取决于jetty-io 9.2.20,而在pom.xml中则没有这样的东西。

然后我将jetty-maven-plugin9.4.3.v20170317降级为9.2.20.v20161216,问题就消失了。

我的pom.xml

<properties>
        <jetty.version>9.2.20.v20161216</jetty.version>
</properties>

...

<plugin>
            <!-- if jetty 7,8 use groupId org.mortbay.jetty, if jetty 9 use org.eclipse.jetty -->
            <!--
            <groupId>org.mortbay.jetty</groupId>
-->
            <groupId>org.eclipse.jetty</groupId> 
            <artifactId>jetty-maven-plugin</artifactId>
            <version>${jetty.version}</version>
            <configuration>
                <jvmArgs>-Xmx2048m -Xms1536m -XX:PermSize=256m -XX:MaxPermSize=512m</jvmArgs>
                <webAppSourceDirectory>${project.basedir}/WebContent</webAppSourceDirectory>
                <stopKey>foo</stopKey>
                <stopPort>9999</stopPort>
                <stopWait>5</stopWait>
                <webAppConfig>
                    <contextPath>/</contextPath>
                </webAppConfig>
                <scanIntervalSeconds>1000</scanIntervalSeconds>
            </configuration>

            <executions>
                <execution>
                    <id>start-jetty</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>start</goal>
                    </goals>
                    <configuration>
                        <scanIntervalSeconds>0</scanIntervalSeconds>
                    </configuration>
                </execution>
                <execution>
                    <id>stop-jetty</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                </execution>
            </executions>

            <dependencies>
                <dependency>
                    <groupId>org.codehaus.groovy</groupId>
                    <artifactId>groovy-all</artifactId>
                    <version>2.4.10</version> 
                </dependency>
                <dependency>
                  <groupId>org.eclipse.jetty</groupId>
                  <artifactId>jetty-io</artifactId>
                  <version>${jetty.version}</version>
                </dependency>
            </dependencies>

        </plugin>

答案 3 :(得分:0)

检查您的端口上是否正在运行某些端口,Jetty的默认端口为8080。