Can load-on-startup in web.xml be used to load an arbitrary class on startup?

后端 未结 4 810
旧时难觅i
旧时难觅i 2020-12-28 17:45

How can I load an arbitrary class on startup in Tomcat? I saw load-on-startup tag for web.xml file, but can I use it and how should I implement my

4条回答
  •  甜味超标
    2020-12-28 18:23

    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 :

    
    
    
    
    

    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.

提交回复
热议问题