Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] org.eclipse.jetty.server.handler.ContextHandler cannot be cast to org.eclipse.jetty.servlet.ServletContextHandler

I'm trying another way to try and get spring mvc with an embedded jetty instance.  I found this example on github (https://github.com/s4nchez/jetty-spring-mvc-jar/blob/master/src/main/java/com/sandbox/Sandbox.java) , but it is using an older version of jetty (6.1.9) while I am using 7.6.2.v20120308.

So I used the same code snippet:

     final Server server = new Server(8080);

        final ContextHandler contextHandler = new ContextHandler();
        contextHandler.setContextPath("/");
        server.setHandler(contextHandler);


        final DispatcherServlet dispatcherServlet = new DispatcherServlet();
        dispatcherServlet.setContextConfigLocation("classpath:web-context.xml");

        final ServletHandler servletHandler = new ServletHandler();
        servletHandler.addServletWithMapping(new ServletHolder(dispatcherServlet), "/*");

        contextHandler.setHandler(servletHandler);

        server.start();

        server.join();


*** The github code uses import org.mortbay.jetty.handler.ContextHandler; while I am using: import org.eclipse.jetty.server.handler.ContextHandler;
Everything compiles fine, but this is the issue it seems?? (see error output below)


It also uses this in the pom.xml (com.my.path.to.main was changed to the actual one)

 <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>1.7.1</version> <!-- TODO -->
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <filters>
                                <filter>
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.testing.JettyServer</mainClass>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/spring.handlers</resource>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/spring.schemas</resource>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>


When I run java -jar myjar.jar I get this error:


2012-08-29 22:02:36,709 [main] INFO  org.eclipse.jetty.server.Server - jetty-7.x.y-SNAPSHOT
2012-08-29 22:02:36,796 [main] WARN  org.eclipse.jetty.util.component.AbstractLifeCycle - FAILED org.eclipse.jetty.servlet.ServletHandler@8888e6c: java.lang.ClassCastException: org.eclipse.jetty.server.handler.ContextHandler cannot be cast to org.eclipse.jetty.servlet.ServletContextHandler
java.lang.ClassCastException: org.eclipse.jetty.server.handler.ContextHandler cannot be cast to org.eclipse.jetty.servlet.ServletContextHandler
at org.eclipse.jetty.servlet.ServletHandler.doStart(ServletHandler.java:147)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:90)
at org.eclipse.jetty.server.handler.ScopedHandler.doStart(ScopedHandler.java:97)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:722)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:676)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:90)
at org.eclipse.jetty.server.Server.doStart(Server.java:261)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
at com.testing.JettyServer.main(HttpServer.java:52)
2012-08-29 22:02:36,799 [main] WARN  org.eclipse.jetty.util.component.AbstractLifeCycle - FAILED o.e.j.s.h.ContextHandler{/,null}: java.lang.ClassCastException: org.eclipse.jetty.server.handler.ContextHandler cannot be cast to org.eclipse.jetty.servlet.ServletContextHandler
java.lang.ClassCastException: org.eclipse.jetty.server.handler.ContextHandler cannot be cast to org.eclipse.jetty.servlet.ServletContextHandler
at org.eclipse.jetty.servlet.ServletHandler.doStart(ServletHandler.java:147)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:90)
at org.eclipse.jetty.server.handler.ScopedHandler.doStart(ScopedHandler.java:97)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:722)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:676)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:90)
at org.eclipse.jetty.server.Server.doStart(Server.java:261)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
at com.testing.JettyServer.main(HttpServer.java:52)


Now in the 


Back to the top