I use jetty6 in simple application as embedded servlet container. I decided to update it to Jetty 8.
In jetty 6 it was pretty simple to start the server:
Server server = new Server(8080);
Context context = new Context(server, "/", Context.SESSIONS);
context.addServlet(MyServlet.class, "/communication-service");
server.start();
but it doesn't work in Jetty8.
Unfortunately I can't find any simple example for this version. Can't instantiate Context with error
an enclosing instance that contains
org.eclipse.jetty.server.handler.ContextHandler.Context is required
because now it is an inner class and also no such constructor.
Most examples are for jetty 6 and 7.
Could you please provide simple example how to start servlet at jetty 8?
Best Answer
This is the Jetty 8 equivalent to your code. It's still just as simple as it was before, however the API has changed slightly.
If this isn't working for you, then you probably have a classpath issue - Jetty 8 is separated into a lot of independent jar files, and you will need a number of them. At the very least you need:
If you have those jars, then this code should work fine: