jersey
jersey copied to clipboard
Unable to integrate Jersey with Jetty Embedded server
Jetty Versions
jetty-server: 12.0.2
jetty-servlet: 11.0.17
jetty-util: 12.0.2
Jersey versions
jersey-server: 3.1.0-M8
jersey-container-servlet-core: 3.1.0-M8
jersey-container-jetty-http: 3.1.0-M8
jersey-hk2: 3.1.0-M8
jakarta.annotation-api: 3.1.0-M8
Java version/vendor
java 17.0.8
OS type/version
Mac
Description
try {
// we created handler without sessions, because REST is stateless.
var contextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
// Sets application path to the root.
contextHandler.setContextPath("/");
jettyServer.setHandler(contextHandler);
// Adds Servlet that will handle requests on /api/*
ServletHolder jerseyServlet = contextHandler.addServlet(ServletContainer.class, "/api/*");
jerseyServlet.setInitOrder(0);
// set package where rest resources are located.
jerseyServlet.setInitParameter("jersey.config.server.provider.packages",
"com.ashok.gateway.rest.controller");
jettyServer.start();
LOG.error("Jetty Server started...!!");
jettyServer.join();
} catch (Exception e) {
LOG.error("Exception while starting jetty server. {}", e.getMessage(), e);
Thread.currentThread().interrupt();
try {
jettyServer.stop();
} catch (Exception ex) {
LOG.error("Exception while stoping jetty server. {}", ex.getMessage(), ex);
}
jettyServer.destroy();
}
I am using above code to handle REST requests. Above code works fine in Jetty 11.x jars. But when i update jetty versions to 12.x above code compilation is failed. Gives following errors.
[ERROR] /src/main/java/com/ashok/gateway/jetty/JettyApiServer.java:[45,69] cannot access jakarta.servlet.http.HttpServlet
[ERROR] class file for jakarta.servlet.http.HttpServlet not found
[ERROR] /src/main/java/com/ashok/gateway/jetty/JettyApiServer.java:[46,38] cannot access org.eclipse.jetty.server.UserIdentity
[ERROR] class file for org.eclipse.jetty.server.UserIdentity not found
[ERROR] -> �[1m[Help 1]�[m
First, you should probably not mix Jetty 11 and 12 jars. Second, Jetty 12 would be supported since Jersey 3.1.4.
@jansupol thank you for your response. I am using the all the latest jetty jars. and I didn't find Jersey 3.1.4 dependencies in the maven repo. Could you please help me any sample examples to develop REST application using Jetty 12 dependencies.
Jersey 3.1.4 is not released, yet.
@jansupol thanks for your response. Is there any tentative timeline to release 3.1.4? Please let me know. Thanks in advance.
Assumingly 2-3 weeks,
@ashok-mariyala The Jetty team did a huge refactoring in Jetty 12 and removed the servlet classes from the Jetty core. This allows the use of different servlet versions with the same Jetty core.
The correct new servlet artifact for Jersey 3.1 (Jakarta EE 10) is jetty-ee10-servlet
.