load-on-startup problem tomcat












0















I want to load a class on tomcat startup which will actually initialize variables in other classes.



i have edited the appName/WEB-INF/web.xml as follows



<servlet>
<servlet-name>LoadConfigurations</servlet-name>
<servlet-class>Loader.LoadConfigurations</servlet-class>
<init-param>
<param-name>env</param-name>
<param-value>dev</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>


and i have placed my servlet LoadConfiguration in /appName/WEB-INF/classes



how do i check whether the servlet is beig called or not ? because when i try to display the value from initialized class it returns null










share|improve this question























  • try keeping logs or System.out.println("Inside Constuctor") inside constructor and init() method start and end. check if you are getting the logs.

    – Jayesh
    Jul 29 '13 at 6:29
















0















I want to load a class on tomcat startup which will actually initialize variables in other classes.



i have edited the appName/WEB-INF/web.xml as follows



<servlet>
<servlet-name>LoadConfigurations</servlet-name>
<servlet-class>Loader.LoadConfigurations</servlet-class>
<init-param>
<param-name>env</param-name>
<param-value>dev</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>


and i have placed my servlet LoadConfiguration in /appName/WEB-INF/classes



how do i check whether the servlet is beig called or not ? because when i try to display the value from initialized class it returns null










share|improve this question























  • try keeping logs or System.out.println("Inside Constuctor") inside constructor and init() method start and end. check if you are getting the logs.

    – Jayesh
    Jul 29 '13 at 6:29














0












0








0








I want to load a class on tomcat startup which will actually initialize variables in other classes.



i have edited the appName/WEB-INF/web.xml as follows



<servlet>
<servlet-name>LoadConfigurations</servlet-name>
<servlet-class>Loader.LoadConfigurations</servlet-class>
<init-param>
<param-name>env</param-name>
<param-value>dev</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>


and i have placed my servlet LoadConfiguration in /appName/WEB-INF/classes



how do i check whether the servlet is beig called or not ? because when i try to display the value from initialized class it returns null










share|improve this question














I want to load a class on tomcat startup which will actually initialize variables in other classes.



i have edited the appName/WEB-INF/web.xml as follows



<servlet>
<servlet-name>LoadConfigurations</servlet-name>
<servlet-class>Loader.LoadConfigurations</servlet-class>
<init-param>
<param-name>env</param-name>
<param-value>dev</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>


and i have placed my servlet LoadConfiguration in /appName/WEB-INF/classes



how do i check whether the servlet is beig called or not ? because when i try to display the value from initialized class it returns null







java tomcat






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 16 '11 at 21:19









user949550user949550

12




12













  • try keeping logs or System.out.println("Inside Constuctor") inside constructor and init() method start and end. check if you are getting the logs.

    – Jayesh
    Jul 29 '13 at 6:29



















  • try keeping logs or System.out.println("Inside Constuctor") inside constructor and init() method start and end. check if you are getting the logs.

    – Jayesh
    Jul 29 '13 at 6:29

















try keeping logs or System.out.println("Inside Constuctor") inside constructor and init() method start and end. check if you are getting the logs.

– Jayesh
Jul 29 '13 at 6:29





try keeping logs or System.out.println("Inside Constuctor") inside constructor and init() method start and end. check if you are getting the logs.

– Jayesh
Jul 29 '13 at 6:29












4 Answers
4






active

oldest

votes


















1














There are two problems:




  1. The compiled class needs to go into a folder structure base on the package name. In your case a folder called Loader


  2. In order to call the servlet, you need to add a <ServletMapping> to your web.xml file







share|improve this answer































    1














    The container should call your servlets init() method when the servlet is initialized. Implement/override that method and try writing something to the log from there.






    share|improve this answer































      0














      This is the solution for Tomcat 7.0



      Step 1:
      Create war file for your webapp/servlets.
      If you are using Eclipse, File->Export->Web->WAR file, and save it to a known location.



      Step 2:
      Find out the home folder for your tomcat.
      For that, go to tomcat/apache-tomcat-7.0.41/bin and execute ./startup.sh
      This will print out couple of global variable names.
      Note down the one for CATALINA_HOME.



      Step 3:
      Copy the war file from Step 1 in CATALINA_HOME/webapps



      Step 4:
      Next, Create an xml file in CATALINA_HOME/conf/{Engine}/localhost/MyServlets.xml :



      <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
      <Context deployOnStartup="true" docBase="/home/ubuntu/Downloads/apache-tomcat-7.0.42/webapps/" reloadable="true">
      <Manager pathname=""/>
      </Context>


      Change docBase to point to location where you copied the war file in Step 3.



      Now, you can go go to tomcat/apache-tomcat-7.0.41/bin and execute ./startup.sh.
      Your servlets will be automatically started.
      Hope this helps.






      share|improve this answer































        0














        This is how I fix it on tomcat 9:





        1. Edit the conf/context.xml file and add reloadable="false" to the <Context> tag.



          <Context reloadable="false">




        2. Edit the conf/server.xml file and add deployOnStartup="false" to the <Host> tag.



          <Host appBase="webapps" deployOnStartup="false" …>








        share|improve this answer


























          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7450497%2fload-on-startup-problem-tomcat%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          4 Answers
          4






          active

          oldest

          votes








          4 Answers
          4






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          There are two problems:




          1. The compiled class needs to go into a folder structure base on the package name. In your case a folder called Loader


          2. In order to call the servlet, you need to add a <ServletMapping> to your web.xml file







          share|improve this answer




























            1














            There are two problems:




            1. The compiled class needs to go into a folder structure base on the package name. In your case a folder called Loader


            2. In order to call the servlet, you need to add a <ServletMapping> to your web.xml file







            share|improve this answer


























              1












              1








              1







              There are two problems:




              1. The compiled class needs to go into a folder structure base on the package name. In your case a folder called Loader


              2. In order to call the servlet, you need to add a <ServletMapping> to your web.xml file







              share|improve this answer













              There are two problems:




              1. The compiled class needs to go into a folder structure base on the package name. In your case a folder called Loader


              2. In order to call the servlet, you need to add a <ServletMapping> to your web.xml file








              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Sep 16 '11 at 21:25









              nfechnernfechner

              15.1k53960




              15.1k53960

























                  1














                  The container should call your servlets init() method when the servlet is initialized. Implement/override that method and try writing something to the log from there.






                  share|improve this answer




























                    1














                    The container should call your servlets init() method when the servlet is initialized. Implement/override that method and try writing something to the log from there.






                    share|improve this answer


























                      1












                      1








                      1







                      The container should call your servlets init() method when the servlet is initialized. Implement/override that method and try writing something to the log from there.






                      share|improve this answer













                      The container should call your servlets init() method when the servlet is initialized. Implement/override that method and try writing something to the log from there.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Sep 16 '11 at 21:26









                      Juha PalomäkiJuha Palomäki

                      22.5k22938




                      22.5k22938























                          0














                          This is the solution for Tomcat 7.0



                          Step 1:
                          Create war file for your webapp/servlets.
                          If you are using Eclipse, File->Export->Web->WAR file, and save it to a known location.



                          Step 2:
                          Find out the home folder for your tomcat.
                          For that, go to tomcat/apache-tomcat-7.0.41/bin and execute ./startup.sh
                          This will print out couple of global variable names.
                          Note down the one for CATALINA_HOME.



                          Step 3:
                          Copy the war file from Step 1 in CATALINA_HOME/webapps



                          Step 4:
                          Next, Create an xml file in CATALINA_HOME/conf/{Engine}/localhost/MyServlets.xml :



                          <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
                          <Context deployOnStartup="true" docBase="/home/ubuntu/Downloads/apache-tomcat-7.0.42/webapps/" reloadable="true">
                          <Manager pathname=""/>
                          </Context>


                          Change docBase to point to location where you copied the war file in Step 3.



                          Now, you can go go to tomcat/apache-tomcat-7.0.41/bin and execute ./startup.sh.
                          Your servlets will be automatically started.
                          Hope this helps.






                          share|improve this answer




























                            0














                            This is the solution for Tomcat 7.0



                            Step 1:
                            Create war file for your webapp/servlets.
                            If you are using Eclipse, File->Export->Web->WAR file, and save it to a known location.



                            Step 2:
                            Find out the home folder for your tomcat.
                            For that, go to tomcat/apache-tomcat-7.0.41/bin and execute ./startup.sh
                            This will print out couple of global variable names.
                            Note down the one for CATALINA_HOME.



                            Step 3:
                            Copy the war file from Step 1 in CATALINA_HOME/webapps



                            Step 4:
                            Next, Create an xml file in CATALINA_HOME/conf/{Engine}/localhost/MyServlets.xml :



                            <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
                            <Context deployOnStartup="true" docBase="/home/ubuntu/Downloads/apache-tomcat-7.0.42/webapps/" reloadable="true">
                            <Manager pathname=""/>
                            </Context>


                            Change docBase to point to location where you copied the war file in Step 3.



                            Now, you can go go to tomcat/apache-tomcat-7.0.41/bin and execute ./startup.sh.
                            Your servlets will be automatically started.
                            Hope this helps.






                            share|improve this answer


























                              0












                              0








                              0







                              This is the solution for Tomcat 7.0



                              Step 1:
                              Create war file for your webapp/servlets.
                              If you are using Eclipse, File->Export->Web->WAR file, and save it to a known location.



                              Step 2:
                              Find out the home folder for your tomcat.
                              For that, go to tomcat/apache-tomcat-7.0.41/bin and execute ./startup.sh
                              This will print out couple of global variable names.
                              Note down the one for CATALINA_HOME.



                              Step 3:
                              Copy the war file from Step 1 in CATALINA_HOME/webapps



                              Step 4:
                              Next, Create an xml file in CATALINA_HOME/conf/{Engine}/localhost/MyServlets.xml :



                              <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
                              <Context deployOnStartup="true" docBase="/home/ubuntu/Downloads/apache-tomcat-7.0.42/webapps/" reloadable="true">
                              <Manager pathname=""/>
                              </Context>


                              Change docBase to point to location where you copied the war file in Step 3.



                              Now, you can go go to tomcat/apache-tomcat-7.0.41/bin and execute ./startup.sh.
                              Your servlets will be automatically started.
                              Hope this helps.






                              share|improve this answer













                              This is the solution for Tomcat 7.0



                              Step 1:
                              Create war file for your webapp/servlets.
                              If you are using Eclipse, File->Export->Web->WAR file, and save it to a known location.



                              Step 2:
                              Find out the home folder for your tomcat.
                              For that, go to tomcat/apache-tomcat-7.0.41/bin and execute ./startup.sh
                              This will print out couple of global variable names.
                              Note down the one for CATALINA_HOME.



                              Step 3:
                              Copy the war file from Step 1 in CATALINA_HOME/webapps



                              Step 4:
                              Next, Create an xml file in CATALINA_HOME/conf/{Engine}/localhost/MyServlets.xml :



                              <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
                              <Context deployOnStartup="true" docBase="/home/ubuntu/Downloads/apache-tomcat-7.0.42/webapps/" reloadable="true">
                              <Manager pathname=""/>
                              </Context>


                              Change docBase to point to location where you copied the war file in Step 3.



                              Now, you can go go to tomcat/apache-tomcat-7.0.41/bin and execute ./startup.sh.
                              Your servlets will be automatically started.
                              Hope this helps.







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Jul 29 '13 at 6:22









                              Priyank DesaiPriyank Desai

                              2,1341914




                              2,1341914























                                  0














                                  This is how I fix it on tomcat 9:





                                  1. Edit the conf/context.xml file and add reloadable="false" to the <Context> tag.



                                    <Context reloadable="false">




                                  2. Edit the conf/server.xml file and add deployOnStartup="false" to the <Host> tag.



                                    <Host appBase="webapps" deployOnStartup="false" …>








                                  share|improve this answer






























                                    0














                                    This is how I fix it on tomcat 9:





                                    1. Edit the conf/context.xml file and add reloadable="false" to the <Context> tag.



                                      <Context reloadable="false">




                                    2. Edit the conf/server.xml file and add deployOnStartup="false" to the <Host> tag.



                                      <Host appBase="webapps" deployOnStartup="false" …>








                                    share|improve this answer




























                                      0












                                      0








                                      0







                                      This is how I fix it on tomcat 9:





                                      1. Edit the conf/context.xml file and add reloadable="false" to the <Context> tag.



                                        <Context reloadable="false">




                                      2. Edit the conf/server.xml file and add deployOnStartup="false" to the <Host> tag.



                                        <Host appBase="webapps" deployOnStartup="false" …>








                                      share|improve this answer















                                      This is how I fix it on tomcat 9:





                                      1. Edit the conf/context.xml file and add reloadable="false" to the <Context> tag.



                                        <Context reloadable="false">




                                      2. Edit the conf/server.xml file and add deployOnStartup="false" to the <Host> tag.



                                        <Host appBase="webapps" deployOnStartup="false" …>









                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Nov 16 '18 at 11:35

























                                      answered Nov 16 '18 at 10:29









                                      Unai ViviUnai Vivi

                                      2,37232044




                                      2,37232044






























                                          draft saved

                                          draft discarded




















































                                          Thanks for contributing an answer to Stack Overflow!


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid



                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.


                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function () {
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7450497%2fload-on-startup-problem-tomcat%23new-answer', 'question_page');
                                          }
                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown







                                          Popular posts from this blog

                                          Bressuire

                                          Vorschmack

                                          Quarantine