aspose file tools*
The moose likes Web Services and the fly likes How to Start a service automatically when the tomcat starts? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "How to Start a service automatically when the tomcat starts?" Watch "How to Start a service automatically when the tomcat starts?" New topic
Author

How to Start a service automatically when the tomcat starts?

Muralidharan Raju
Greenhorn

Joined: Feb 24, 2011
Posts: 25

Hey folks,

i need to run an application that can run automatically that when the tomcat starts..?
any suggestions...?
Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 518
    
    2

Muralidharan Raju wrote:Hey folks,

i need to run an application that can run automatically that when the tomcat starts..?
any suggestions...?


Hi Muralidharan,

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.


Regards
KumarRaja

Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
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:

Best wishes!


My free books and tutorials: http://www.slideshare.net/krizsan
Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 518
    
    2

Hi Ivan,

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.
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
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.
Best wishes!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Start a service automatically when the tomcat starts?