How to get Netbeans 9 to deploy a valid webapp on

2020-02-01 12:22发布

问题:

I have a working Tomcat instance running;

  • Tomcat 9.0.10
  • OpenJDK 10.0.2

I have a working Netbeans 8.2 project compiled on Library JDK1.8, This builds and deploys and runs on the above server fine.

I am now trying to move to Netbeans 9, so I have a that running on the OpenJDK 10.0.2 JDK. If I build the same project (still on Library JDK1.8), it builds and deploys fine. However, when it runs on the same server I get the following error;

javax.servlet.ServletException: Error instantiating servlet class [xxxx.xxx.xxx.TestServlet]
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:491)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668)
    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:764)
    org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1388)
    org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
    java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.base/java.lang.Thread.run(Thread.java:844)
Root Cause

java.lang.RuntimeException: 
    xxxx.xxx.xxx.TestServlet.<init>(TestServlet.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:488)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:491)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668)
    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:764)
    org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1388)
    org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
    java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.base/java.lang.Thread.run(Thread.java:844)
Note The full stack trace of the root cause is available in the server logs.

(xxxx.xxx.xxx.TestServlet replaced for real Servlet class)

It complaints about the first line of the Servlet which is actaully the "/*" of the template comment anyway.

I would have thought that which ever Netbeans I was using, if both were compiled again the same JDK1.8 JDK, both deployed WAR should be the same and both work. Netbeans 9 seems to be building something different and the error reported is not really much help.

Any clues?

回答1:

First, note that Netbeans 9.0 RC1 only supports Java SE development...

Release 9.0, which will be an IDE for Java SE development only, the other features have not been donated yet by Oracle and are being audited and processed and be part of subsequent releases of Apache NetBeans.

That said, earlier beta releases of Apache NetBeans 9 provided plugins to allow Java EE applications to be built, and that functionality will be reintroduced once NetBeans 9.0 is released:

Oracle has audited and donated all the modules for features providing support for JavaScript, PHP, Groovy, and enterprise Java (i.e., Java EE or, as it is known now, Jakarta EE). These features are on a separate branch in the Apache NetBeans Git repo. They will be integrated, i.e., relicensed to Apache, after Apache NetBeans (incubating) 9.0 is released.

You didn't specify which version of NetBeans 9 you are using (there have been many in the past few months), but if you download NetBeans 9.0 RC1 it does not provide a wizard to create Java Web applications, nor is it possible to add an application server such as Tomcat or Wildfly, nor are any suitable plugins offered. So presumably anything outside the scope of Java SE, such as the deployment of web applications, is not formally supported.

However, you can still manually add plugins (at your own risk) to enable Java EE functionality in Apache NetBeans 9.0:

  • Tools > Plugins > Settings tab > click the Add button
  • On the Update Center Customizer screen enter some value in the Name field (e.g. "My plugins"), http://updates.netbeans.org/netbeans/updates/8.2/uc/final/distribution/catalog.xml.gz in the URL field, and click OK.
  • This should create a new entry in the Configuration of Update Centers list in the Settings tab.
  • Checking that new entry should instantly add plugins to the Available Plugins tab. In my case it added 43 entries.
  • Click the Available Plugins tab, then click the Category column to sort the entries by category.
  • Check all the entries for category Java Web and EE, and then click the Install button.
  • The plugins will be downloaded and installed. To confirm that, click the Installed tab. You should see the plugins you just added, such as Java EE Base and RESTful Web Services.

After that you should have Java EE functionality properly enabled. So can you add that functionality and then retry your deployment and advise?



回答2:

This also works in Netbeans 10, and allows you to install the Payara plugins (Payara, Payara Micro) which are far superior to Tomcat IMHO.