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
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.