@WebServlet fails in GlassFish 5 + JDK 13 with java.lang.RuntimeException: com.example.NewServlet.<init>(NewServlet.java:1), always at line 1

纵饮孤独 提交于 2021-01-13 09:10:16

问题


JSPs and html files are served by my Glassfish server in NetBeans, but not servlets. Latest NetBeans is configured to use JDK latest 13, and Glassfish is using Java EE 1.8

Error reported in the browser:

    HTTP Status 500 - Internal Server Error    
    
    type Exception report
    message
Internal Server Error
    description
The server encountered an internal error that prevented it from fulfilling this request.
    exception
    javax.servlet.ServletException: Error instantiating servlet class com.example.NewServlet
    root cause
    com.sun.enterprise.container.common.spi.util.InjectionException: Error creating managed object for class: class com.example.NewServlet
    root cause
    java.lang.RuntimeException:
    note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 5.1.0 logs.

Error reported on the server (note that it's always at line 1 of the sevlet class! this is where normally the package is declared):

 StandardWrapperValve[NewServlet]: Allocate exception for servlet NewServlet
java.lang.RuntimeException:
 at com.example.NewServlet.<init>(NewServlet.java:1)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
 at org.jboss.weld.injection.ConstructorInjectionPoint.newInstance(ConstructorInjectionPoint.java:119)
 at org.jboss.weld.injection.ConstructorInjectionPoint.invokeAroundConstructCallbacks(ConstructorInjectionPoint.java:92)
 at org.jboss.weld.injection.ConstructorInjectionPoint.newInstance(ConstructorInjectionPoint.java:78)
 at org.jboss.weld.injection.producer.AbstractInstantiator.newInstance(AbstractInstantiator.java:28)
 at org.jboss.weld.injection.producer.BasicInjectionTarget.produce(BasicInjectionTarget.java:112)
 at org.jboss.weld.injection.producer.BeanInjectionTarget.produce(BeanInjectionTarget.java:180)
 at org.glassfish.weld.services.JCDIServiceImpl.createManagedObject(JCDIServiceImpl.java:435)
 at org.glassfish.weld.services.JCDIServiceImpl.createManagedObject(JCDIServiceImpl.java:293)
 at com.sun.enterprise.container.common.impl.managedbean.ManagedBeanManagerImpl.createManagedBean(ManagedBeanManagerImpl.java:453)
 at com.sun.enterprise.container.common.impl.managedbean.ManagedBeanManagerImpl.createManagedBean(ManagedBeanManagerImpl.java:406)
 at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.createManagedObject(InjectionManagerImpl.java:312)
 at com.sun.enterprise.web.WebContainer.createServletInstance(WebContainer.java:725)
 at com.sun.enterprise.web.WebModule.createServletInstance(WebModule.java:1955)
 at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1262)
 at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:1069)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:136)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:119)
 at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:611)
 at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:550)
 at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:75)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:114)
 at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:332)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:199)
 at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:439)
 at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:144)
 at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:182)
 at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:156)
 at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:218)
 at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:95)
 at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:260)
 at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:177)
 at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:109)
 at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:88)
 at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:53)
 at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:515)
 at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:89)
 at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:94)
 at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:33)
 at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:114)
 at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:569)
 at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:549)
 at java.lang.Thread.run(Thread.java:748)

Untouched servlet shell generated by Netbeans:

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>
}

Looking at the solution to a vaguely similar post, also tried adding a no-argument constructor:

public NewServlet() {
        super();
}

Shenanigans in the Glassfish startup:

Launching GlassFish on Felix platform
INFO: Create bundle provisioner class = class com.sun.enterprise.glassfish.bootstrap.osgi.BundleProvisioner.
WARNING: Skipping entry  because it is not an absolute URI.
WARNING: Skipping entry  because it is not an absolute URI.
Registered com.sun.enterprise.glassfish.bootstrap.osgi.EmbeddedOSGiGlassFishRuntime@3b4af5 in service registry.
#!## LogManagerService.postConstruct : rootFolder=D:\GlassfishDownload\glassfish
#!## LogManagerService.postConstruct : templateDir=D:\GlassfishDownload\glassfish\lib\templates
#!## LogManagerService.postConstruct : src=D:\GlassfishDownload\glassfish\lib\templates\logging.properties
#!## LogManagerService.postConstruct : dest=D:\GlassfishDownload\glassfish\domains\domain1\config\logging.properties
  Running GlassFish Version: GlassFish Server Open Source Edition  5.1.0  (build default-private)|#]
  Server log file is using Formatter class: com.sun.enterprise.server.logging.ODLLogFormatter|#]
  Realm [admin-realm] of classtype [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.|#]
  Realm [file] of classtype [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.|#]
  Realm [certificate] of classtype [com.sun.enterprise.security.auth.realm.certificate.CertificateRealm] successfully created.|#]
  Registered org.glassfish.ha.store.adapter.cache.ShoalBackingStoreProxy for persistence-type = replicated in BackingStoreFactoryRegistry|#]
  Authorization Service has successfully initialized.|#]
  JTS5014: Recoverable JTS instance, serverId = [100]|#]
  Grizzly Framework 2.4.4 started in: 81ms - bound to [/0.0.0.0:8080]|#]
  Grizzly Framework 2.4.4 started in: 5ms - bound to [/0.0.0.0:8181]|#]
  Grizzly Framework 2.4.4 started in: 5ms - bound to [/0.0.0.0:4848]|#]
  Grizzly Framework 2.4.4 started in: 5ms - bound to [/0.0.0.0:3700]|#]
  visiting unvisited references|#]
  HV000001: Hibernate Validator 6.0.10.Final|#]
  Grizzly Framework 2.4.4 started in: 6ms - bound to [/0.0.0.0:8080]|#]
  Grizzly Framework 2.4.4 started in: 7ms - bound to [/0.0.0.0:8181]|#]
  Java security manager is disabled.|#]
  Entering Security Startup Service.|#]
  Loading policy provider com.sun.enterprise.security.provider.PolicyWrapper.|#]
  Security Service(s) started successfully.|#]
  Created HTTP listener http-listener-1 on host/port 0.0.0.0:8080|#]
  Created HTTP listener http-listener-2 on host/port 0.0.0.0:8181|#]
  Created HTTP listener admin-listener on host/port 0.0.0.0:4848|#]
  Created virtual server server|#]
  Created virtual server __asadmin|#]
  Setting JAAS app name glassfish-web|#]
  Virtual server server loaded default web module |#]
  visiting unvisited references|#]
  visiting unvisited references|#]
  visiting unvisited references|#]
  visiting unvisited references|#]
  WELD-000900: 3.0.0 (Final)|#]
  WELD-000411: Observer method [BackedAnnotatedMethod] public org.hibernate.validator.cdi.ValidationExtension.processAnnotatedType(@Observes ProcessAnnotatedType<T>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.|#]
  WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType<T>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.|#]
  WELD-000411: Observer method [BackedAnnotatedMethod] org.glassfish.sse.impl.ServerSentEventCdiExtension.processAnnotatedType(@Observes ProcessAnnotatedType<T>, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.|#]
  WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider.processAnnotatedType(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.|#]
  Listening to REST requests at context: /management/domain.|#]
  WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class com.ibm.jbatch.container.cdi.BatchProducerBean is deprecated from CDI 1.1!|#]
  WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.jersey.ext.cdi1x.transaction.internal.WebAppExceptionHolder is deprecated from CDI 1.1!|#]
  WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.jersey.ext.cdi1x.transaction.internal.WebAppExceptionInterceptor is deprecated from CDI 1.1!|#]
  WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.jersey.ext.cdi1x.transaction.internal.TransactionalExceptionMapper is deprecated from CDI 1.1!|#]
  WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider$JaxRsParamProducer is deprecated from CDI 1.1!|#]
  WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class com.sun.faces.flow.FlowDiscoveryCDIHelper is deprecated from CDI 1.1!|#]
  WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.cdi.transaction.TransactionalInterceptorMandatory is deprecated from CDI 1.1!|#]
  WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.cdi.transaction.TransactionalInterceptorNever is deprecated from CDI 1.1!|#]
  WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.cdi.transaction.TransactionalInterceptorNotSupported is deprecated from CDI 1.1!|#]
  WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.cdi.transaction.TransactionalInterceptorRequired is deprecated from CDI 1.1!|#]
  WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.cdi.transaction.TransactionalInterceptorRequiresNew is deprecated from CDI 1.1!|#]
  WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.cdi.transaction.TransactionalInterceptorSupports is deprecated from CDI 1.1!|#]
  WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.jersey.ext.cdi1x.servlet.internal.CdiExternalRequestScope is deprecated from CDI 1.1!|#]
  Initializing Soteria 1.0.1 for context '/BackToTech'|#]
  Initializing Mojarra 2.3.9 for context '/BackToTech'|#]
  Loading application [BackToTech] at [/BackToTech]|#]
  Loading application BackToTech done in 17,036 ms|#]
  GlassFish Server Open Source Edition  5.1.0  (default-private) startup time : Felix (9,720ms), startup services(18,529ms), total(28,249ms)|#]
  Grizzly Framework 2.4.4 started in: 21ms - bound to [/0.0.0.0:7676]|#]
  visiting unvisited references|#]
  Registered com.sun.enterprise.glassfish.bootstrap.osgi.EmbeddedOSGiGlassFishImpl@b224cd as OSGi service registration: org.apache.felix.framework.ServiceRegistrationImpl@1ee25f1.|#]
  JMXStartupService has started JMXConnector on JMXService URL service:jmx:rmi://DESKTOP-2IGRR7A:8686/jndi/rmi://DESKTOP-2IGRR7A:8686/jmxrmi|#]
  Created HTTP listener http-listener-2 on host/port 0.0.0.0:8181|#]
  Grizzly Framework 2.4.4 started in: 7ms - bound to [/0.0.0.0:8181]|#]
  Created HTTP listener http-listener-1 on host/port 0.0.0.0:8080|#]
  Grizzly Framework 2.4.4 started in: 13ms - bound to [/0.0.0.0:8080]|#]
  visiting unvisited references|#]
  visiting unvisited references|#]
  visiting unvisited references|#]
  visiting unvisited references|#]
  visiting unvisited references|#]
  visiting unvisited references|#]
  visiting unvisited references|#]
  visiting unvisited references|#]
  WELD-000411: Observer method [BackedAnnotatedMethod] org.glassfish.sse.impl.ServerSentEventCdiExtension.processAnnotatedType(@Observes ProcessAnnotatedType<T>, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.|#]
  WELD-000411: Observer method [BackedAnnotatedMethod] public org.hibernate.validator.cdi.ValidationExtension.processAnnotatedType(@Observes ProcessAnnotatedType<T>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.|#]
  WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType<T>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.|#]
  WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider.processAnnotatedType(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.|#]
  WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.cdi.transaction.TransactionalInterceptorMandatory is deprecated from CDI 1.1!|#]
  WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.cdi.transaction.TransactionalInterceptorNever is deprecated from CDI 1.1!|#]
  WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.cdi.transaction.TransactionalInterceptorNotSupported is deprecated from CDI 1.1!|#]
  WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.cdi.transaction.TransactionalInterceptorRequired is deprecated from CDI 1.1!|#]
  WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.cdi.transaction.TransactionalInterceptorRequiresNew is deprecated from CDI 1.1!|#]
  WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.cdi.transaction.TransactionalInterceptorSupports is deprecated from CDI 1.1!|#]
  WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class com.ibm.jbatch.container.cdi.BatchProducerBean is deprecated from CDI 1.1!|#]
  WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.jersey.ext.cdi1x.transaction.internal.WebAppExceptionHolder is deprecated from CDI 1.1!|#]
  WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.jersey.ext.cdi1x.transaction.internal.WebAppExceptionInterceptor is deprecated from CDI 1.1!|#]
  WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.jersey.ext.cdi1x.transaction.internal.TransactionalExceptionMapper is deprecated from CDI 1.1!|#]
  WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider$JaxRsParamProducer is deprecated from CDI 1.1!|#]
  WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class com.sun.faces.flow.FlowDiscoveryCDIHelper is deprecated from CDI 1.1!|#]
  WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.jersey.ext.cdi1x.servlet.internal.CdiExternalRequestScope is deprecated from CDI 1.1!|#]

回答1:


Assuming that "Latest NetBeans" refers to NetBeans 11.2, the Glassfish problem arises from running NetBeans using JDK 13. There is nothing directly wrong with that approach; it is explicitly supported from NetBeans 11.2 onwards.

However, it means that when you start your Glassfish 5 server within NetBeans it will also be using Java 13. See NetBeans Bug Report NETBEANS-2256 NetBeans 11 vc3: Unable to manage GlassFish 5.1 when running NetBeans using any JDK greater than JDK 8 which states:

If I run Apache NetBeans using JDK 9+, then I am unable to manage GlassFish server or deployments to GlassFish server from within the IDE. GlassFish 5+ currently only supports JDK 8...

This issue is not confined to the NetBeans IDE. For example, see Eclipse Glassfish/Payara does not recognize my JDK.

Your options are:

  • Edit netbeans.conf to make JDK 8 the default Java version for NetBeans 11.x. See this SO answer for details on how to do that. Note that this doesn't prevent you adding JDK 13 as a second Java platform within NetBeans (using Tools > Java Platforms > Add Platform...) for your projects. If you do this, ensure that your update version of JDK 8 is compatible with your version of Glassfish 5.x, as specified in this helpful SO answer.
  • Use an alternative application server within NetBeans 11.2 when using JDK 13. For example Wildfly 18+ supports the use of JDK 13.



回答2:


Netbeans 12 have a property configuration in Server COnfiguration , I tried to config Glassfish 5.1 RUn with jdk 11 (jdk 13 is not permitted ) but it doesn't work anyway



来源:https://stackoverflow.com/questions/60493004/webservlet-fails-in-glassfish-5-jdk-13-with-java-lang-runtimeexception-com-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!