I'm trying another way to try and get spring mvc with an embedded jetty instance. I found this example on github (
) while I am using 7.6.2.v20120308.
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();
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>
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)