This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
When hitting "run" the webapp gets loaded twice in many situations. This is a problem if your webapp has servlets that do non-trivial work at initialization time. To Reproduce: 1) Create a new "Web" application specifying Tomcat as the server (Tomcat 6.0.16 in my case but I don't believe this problem is version specific). 2) Use the built-in wizard to add a new Servlet class. (Mine is called "NewServlet"). 3) Add this method to NewServlet: public void init() { System.out.println("newservlet started");} 4) Open web.xml and set the "startup order" to 1 for "NewServlet". (This equates to <load-on-startup>1</load-on-startup>) 5) Click Run->Debug Main Project 6) You should see "newservlet started" in the output. 7) Click the orange square to stop the Tomcat server (the one on Tomcat's output tab) 8) Make any change to NewServlet.java (I suggest editing the printed init text). 9) Click Run->Debug Main Project 10) You will see the print out twice :( Of course in this example it's harmless but consider if your servlet had to do some complex and time consuming startup preparations (as my company's webapp does). A fix for this would be greatly appreciated.
What you are actually doing is: 1) Create a new "Web" application specifying Tomcat as the server (Tomcat 6.0.16 in my case but I don't believe this problem is version specific). 2) Use the built-in wizard to add a new Servlet class. (Mine is called "NewServlet"). 3) Add this method to NewServlet: public void init() { System.out.println("newservlet started");} 4) Open web.xml and set the "startup order" to 1 for "NewServlet". (This equates to <load-on-startup>1</load-on-startup>) 5) Click Run->Debug Main Project - tomcat is starting - tomcat is fully started - app is deployed so the init is called, init prints the output 6) You should see "newservlet started" in the output. 7) Click the orange square to stop the Tomcat server (the one on Tomcat's output tab) 8) Make any change to NewServlet.java (I suggest editing the printed init text). 9) Click Run->Debug Main Project - tomcat is starting again, loads the deployed application, init prints the output - tomcat is fully started - changed servlet is deployed so the init on instance of different class has to be called, init prints the output 10) You will see the print out twice :( Just don't do step 7. The behaviour is perfectly logical. BTW I'm not sure it is wise to perform long operation on every init because there is no guarantee in specification how long the servlet instance will live. Init can be called many times (on different instances of course).
(In reply to comment #1) > What you are actually doing is: > > 1) Create a new "Web" application specifying Tomcat as the server (Tomcat > 6.0.16 in my case but I don't believe this > problem is version specific). > 2) Use the built-in wizard to add a new Servlet class. (Mine is called > "NewServlet"). > 3) Add this method to NewServlet: public void init() { > System.out.println("newservlet started");} > 4) Open web.xml and set the "startup order" to 1 for "NewServlet". (This > equates to <load-on-startup>1</load-on-startup>) > 5) Click Run->Debug Main Project > - tomcat is starting > - tomcat is fully started > - app is deployed so the init is called, init prints the output > 6) You should see "newservlet started" in the output. > 7) Click the orange square to stop the Tomcat server (the one on Tomcat's > output tab) > 8) Make any change to NewServlet.java (I suggest editing the printed init > text). > 9) Click Run->Debug Main Project > - tomcat is starting again, loads the deployed application, init prints the > output > - tomcat is fully started > - changed servlet is deployed so the init on instance of different class has > to be called, init prints the output > 10) You will see the print out twice :( > > Just don't do step 7. The behaviour is perfectly logical. > > BTW I'm not sure it is wise to perform long operation on every init because > there is no guarantee in specification how > long the servlet instance will live. Init can be called many times (on > different instances of course). "just don't do step 7"? i have the same problem. when i start tomcat from its own startup script, everything is working fine. what does the netbeans do to start app twice?