Reputation: 2255
I am trying to set WebAppContext as Jetty server handler and it fails at the server.setHandler() call. Gives following message in exception. Any help would be highly appreciated.
org.eclipse.jetty.servlet.ServletContextHandler.(Lorg/eclipse/jetty/server/HandlerContainer;Ljava/lang/String;Lorg/eclipse/jetty/server/session/SessionHandler;Lorg/eclipse/jetty/security/SecurityHandler;Lorg/eclipse/jetty/servlet/ServletHandler;Lorg/eclipse/jetty/server/handler/ErrorHandler;I)V
WebAppContext webAppContext = new WebAppContext("samples/webapp", "/");
webAppContext.setConfigurationClasses(new String[]{
"org.eclipse.jetty.webapp.WebInfConfiguration",
"org.eclipse.jetty.webapp.WebXmlConfiguration"});
Server server = new Server(port);
server.setHandler(webAppContext);
server.start();
I am using jetty version 9.2.16.v20160414. Thanks in advance.
SOLVED: This is solved now. There was a dependency conflict
Upvotes: 0
Views: 485
Reputation: 3217
Here is an example from default Wicket 7 quickstart maven set-up. This is from the Start class, which sets up a jetty 9 server for unit testing purposes.
Below is the stripped down version, which is set up in a slightly different manner to yours. Hopefully will be of use to you:
Server server = new Server();
ServerConnector http = new ServerConnector(server);
http.setPort(8080);
server.addConnector(http);
WebAppContext bb = new WebAppContext();
bb.setServer(server);
bb.setContextPath("/");
bb.setWar("src/main/webapp");
server.setHandler(bb);
try
{
server.start();
server.join();
}
catch (Exception e)
{
e.printStackTrace();
System.exit(100);
}
Upvotes: 1
Reputation: 49462
Drop the setConfigurationClasses()
call entirely, and use the defaults.
The code you have is undoing most of the servlet level requirements for WebApps, rending about 80% of the features of webapps invalid.
While it is possible to run with less than default webapp Configuration classes, that kind of operation is very advanced usage. Don't attempt to strip the default Configuration classes unless you intimately know what you are doing, and understand the role of all of the existing Configuration classes first.
If you see code on the web that does this, avoid it (for now).
That being said, if you see code that adds the the default Configuration classes, that's normal.
Note: Jetty is highly modular, and you can setup/tweak environments to some truely stunning modes. Once you start digging into Jetty, you'll see that nothing is required, not even the Server!
This modular nature is unique the world of Java Web Servers, and is the source of much confusion for folks familiar with other servers. The expectations that it "just work" is true, but only in the context of defined defaults. The more you move away from the defaults, the more work you have to do yourself.
Upvotes: 1