Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Resolved
-
None
-
None
-
None
-
Win10, Apache NetBeans IDE 11.0 (Build incubator-netbeans-release-404-on-20190319), apache-tomee-webprofile-8.0.0-M3 or TomCat 9.0.22, or Glassfish 5.0.1
Description
Some kind of nightmare - can not launch primitive servlet on `apache-tomee-webprofile-8.0.0-M3` (the same with TomCat 9.0.22 and Glassfish 5.0.1) and `Apache NetBeans IDE 11.0 (Build incubator-netbeans-release-404-on-20190319)` by using servlet annotations.. Using JDK11. Here is the code:
package com.xsistema; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @WebServlet(name = "NewServlet", urlPatterns = {"/meow"} ) public class NewServlet extends HttpServlet { /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * @param request servlet request @param response servlet response @throws ServletException if a servlet-specific error occurs @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try ( PrintWriter out = response.getWriter()) \{ /* TODO output your page here. You may use following sample code. */ out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet NewServlet</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet NewServlet at " + request.getContextPath() + "</h1>"); out.println("</body>"); out.println("</html>"); } } // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."> /** Handles the HTTP <code>GET</code> method. * @param request servlet request @param response servlet response @throws ServletException if a servlet-specific error occurs @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } /** Handles the HTTP <code>POST</code> method. * @param request servlet request @param response servlet response @throws ServletException if a servlet-specific error occurs @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } /** Returns a short description of the servlet. * @return a String containing servlet description */ @Override public String getServletInfo() { return "Short description"; }// </editor-fold> }
And `web.xml` file:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> </web-app>
The error:
Type Exception Report Message Error instantiating servlet class [com.xsistema.NewServlet] Description The server encountered an unexpected condition that prevented it from fulfilling the request. Exception javax.servlet.ServletException: Error instantiating servlet class [com.xsistema.NewServlet] org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) org.apache.tomee.catalina.OpenEJBSecurityListener$RequestCapturer.invoke(OpenEJBSecurityListener.java:97) org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:836) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1839) org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) java.base/java.lang.Thread.run(Thread.java:834) Root Cause java.lang.RuntimeException: com.xsistema.NewServlet.<init>(NewServlet.java:1) java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) java.base/java.lang.Class.newInstance(Class.java:584) org.apache.openejb.core.WebContext.newWeakableInstance(WebContext.java:147) org.apache.openejb.core.WebContext.newInstance(WebContext.java:181) org.apache.tomee.catalina.JavaeeInstanceManager.newInstance(JavaeeInstanceManager.java:78) org.apache.tomee.catalina.JavaeeInstanceManager.newInstance(JavaeeInstanceManager.java:124) org.apache.tomee.catalina.JavaeeInstanceManager.newInstance(JavaeeInstanceManager.java:119) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) org.apache.tomee.catalina.OpenEJBSecurityListener$RequestCapturer.invoke(OpenEJBSecurityListener.java:97) org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:836) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1839) org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) java.base/java.lang.Thread.run(Thread.java:834)
The goal is to declare servlets only by annotations, like:
@WebServlet(name = "NewServlet", urlPatterns = {"/meow"})
Tested on NetBeans 8.2 with JDK1.8u221 - all works as expected. I suspect the problem is in Apache NetBeans 11, even if project JDK is set to 8 (also source/binary format).