i need to run an application that can run automatically that when the tomcat starts..?
What do you mean by an application here? Since you posted in webservices forum, I assume that you are referring to a webservice. As long as the service is deployed properly in webcontainer, when you start the tomcat, it would automatically starts the service just like any other web application. Please be aware that webservice deployed in webcontainer is nothing but a service wrapped in a servlet which looks for SOAP request over HTTP just like any other servlet.
One basic approach is to configure a servlet to be eagerly loaded by using the <load-on-startup> element in a <servlet> element in the web.xml deployment descriptor or, if you are using Tomcat 7 (or any other container implementing the servlet 3 specification), the loadOnStartup element in the @WebServlet annotation.
In the servlet that is eagerly loaded, you also need an initialization method - this method will be called when the servlet is loaded, which will be when Tomcat is started.
The following is an example of such a servlet using the new servlet 3 annotations:
I'm just curious, if we need to setup load-on-startup explicitly. If the application is deployed, and when the tomcat starts, would this not make the app available implicitly.
Joined: Oct 04, 2006
If an application is deployed and enabled, the it will automatically be available when Tomcat has started up.
The load-on-startup property facilitates eager loading of servlets. If the servlet is not eagerly loaded, then it will still be loaded when a request that matches its URL patter arrives.
Eager loading enables us to eagerly load a servlet which may require long time to, for instance, acquire resources. This to avoid waiting time when the first request arrives.
subject: How to Start a service automatically when the tomcat starts?