sto cercando di sviluppare un server Web incorporando il molo. Quindi con il molo 7.3 tutto ha funzionato bene. Ieri ho aggiornato le librerie del molo alla nuova versione 8.0.3 e ora ottengo un'eccezione creando un ServletContextHandler.Aggiornamento del jetty 7 al jetty 8: java.lang.NoClassDefFoundError: javax/servlet/FilterRegistration
Exception in thread "main" java.lang.NoClassDefFoundError: javax/servlet/FilterRegistration at org.eclipse.jetty.servlet.ServletContextHandler.(ServletContextHandler.java:126) at org.eclipse.jetty.servlet.ServletContextHandler.(ServletContextHandler.java:106) at org.eclipse.jetty.servlet.ServletContextHandler.(ServletContextHandler.java:94) at org.gemsjax.server.GemsJaxServer.main(GemsJaxServer.java:38)
Quindi quello che faccio è:
public static void main(String[] args) {
Server server = new Server(8080);
ServletContextHandler servletContext = new ServletContextHandler(ServletContextHandler.SESSIONS);
servletContext.setContextPath("/servlets");
servletContext.addServlet(new ServletHolder(new CollaborationWebSocketServlet()),"/collaboration");
// The ResourceHandler to handle static web content
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setDirectoriesListed(true);
resourceHandler.setWelcomeFiles(new String[]{ "index.html" });
resourceHandler.setResourceBase("./war/");
ContextHandler resourceContext = new ContextHandler();
resourceContext.setContextPath("/static");
resourceContext.setHandler(resourceHandler);
HandlerCollection handlers = new HandlerCollection();
handlers.addHandler(resourceContext);
handlers.addHandler(servletContext);
server.setHandler(handlers);
try {
server.start();
server.join();
} catch (Exception e) {
e.printStackTrace();
}
}
Così la linea che gettare l'eccezione è:
ServletContextHandler servletContext = new ServletContextHandler(ServletContextHandler.SESSIONS);
Im usando Ubuntu 11.04 con:
versione OpenJDK Java " 1.6.0_22 " OpenJDK Runtime Environment (IcedTea6 1.10.2) (6b22-1.10.2-0ubuntu1 ~ 11.04.1) OpenJDK 64-Bit Server VM (build 20.0-b11, modalità mista)
Qualcuno ha un suggerimento?
grazie per il vostro answere, ma im ancora chiedendo dove l'API servlet 3.0 è disponibile per il download? L'aggiornamento 22 di Java SE JDK 1.6 (openjdk) non fornisce Servlet 3.0? Sono confuso ... – sockeqwe
Hai già scaricato. Jetty 8 è un'implementazione dell'API Servlet 3.0. Devi solo capire che le API Java EE sono ** astratte ** (cioè esistono solo in carta come specifiche e javadoc) e che i contenitori Java EE/Servlet concreti come Jetty, Tomcat, Glassfish, JBoss AS ecc .. etc .. sono le ** implementazioni concrete * (cioè contengono il codice e le librerie). – BalusC
Ok, era il mio errore nel ragionamento. Ho incluso tutte le librerie del molo, ma l'eccezione è ancora lì – sockeqwe