How to get Netbeans 9 to deploy a valid webapp on Tomcat
Asked Answered
T

2

3

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?

Topaz answered 13/7, 2018 at 11:43 Comment(5)
Those stack traces only show that servlet initialization failed. But the message at the end of the RuntimeException trace states "The full stack trace of the root cause is available in the server logs". Can you post the stack trace from Tomcat's log? It should should show more information on that RuntimeException. Also, when you create the 1.8 servlet on NetBeans 9, are you using JDK 8 or JDK 10 to build it?Tricuspid
Those are the full trace logs. I cut from the browser for ease, but the full logs are shown and are same as those in "localhost.2018-07-18.log" on server. "java.lang.RuntimeException: xxxx.xxx.xxx.TestServlet.<init>(TestServlet.java:1)" is the last error. Useless thought it is... your other question. Netbeans 9 is running with JDK10 as it must or it obviously wont run, but the servlet project is build with the same JDK1.8 and the app is built with on netbeans 8.2.Topaz
the war is perfect. If I choose "run" from netbeans 9 to deploy it, it appears to deploy fine an the app appears in tomcat manger but when I run the app I get the error above. However, if i remove the app and install in manually from tomcat manger by picking the war from the dist/ folder it works.... So the issue seems to be related to the way netbeans 9 deploys it to the server. Something in this bust be broken, even though the deploy looks to work fineTopaz
I've posted an answer, which is really more of a very long comment requesting further information. But regarding your comment above on JDK10, it is not required for NetBeans 9 to run.Tricuspid
I'm a NetBeans fan, but in the last months I'm under the impression that it's dying slowly and painfully. I've been trying to use it for web apps, javafx, and others, but achieving this it is so hard that IntelliJ and Eclipse become very good alternatives. Of course, you can try both use the plugins and contribute to the NB9 project, as explained at netbeans.org/community/contribute Maybe you can help it to release more often.Industrialism
T
10

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?

Tricuspid answered 28/7, 2018 at 0:29 Comment(0)
G
0

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

Gav answered 15/2, 2019 at 11:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.