使用maven-jetty-plugin的荒谬ClassCastException

时间:2012-09-14 15:50:57

标签: maven servlets jetty classcastexception maven-jetty-plugin

有谁知道可能导致以下ClassCastException: org.eclipse.jetty.server.Request cannot be cast to org.eclipse.jetty.server.Request

的原因

当我尝试doGet(HttpServletRequest req, ..)

时,我的HttpServletRequest baseRequest = (Request) req;会发生这种情况
<plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>8.1.5.v20120716</version>
    <configuration>
        <jettyXml>src/main/webapp/WEB-INF/jetty.xml</jettyXml>
        <connectors>
            <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
                <port>8081</port>
            </connector>
        </connectors>
            <stopPort>18080</stopPort>
            <stopKey>STOP</stopKey>
        </configuration>
        <dependencies>
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.13</version>
            </dependency>
        </dependencies>
</plugin>

1 个答案:

答案 0 :(得分:2)

您需要确保将jetty-server打包为实际应用程序的一部分;这通常是通过将范围设置为提供来完成的:

<dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-server</artifactId>
    <version>${jetty.version}</version>
    <scope>provided</scope>
</dependency>