You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mehul S Dave <me...@tifr.res.in> on 2001/05/09 08:30:31 UTC

how to execute a .class file automatically when tomcat is started

Hello ,
        I had made our Mailing module . I want that mailing module to be
executed automatically when the Tomcat server is started . Please help me
on how to setup such think without any extra programm to be added
Thanking u


Mehul S Dave
Scientific Officer,
Tata Institute of Fundamental Research
Mumbai .


Re: how to execute a .class file automatically when tomcat is started

Posted by Marco Baringer <ma...@convey.it>.
You'll have to create a servlet and you can tell Tomcat to load (run
it's init() method) it on startup. If the class is called mail.Core
(and it must extend javax.servlet.GenericServlet (or one of its sub
classes))

put this in your app's web.xml:

<servlet>
  <servlet-name>this doesn't matter</servlet-name>
  <servlet-class>mail.Core</servlet-class>
  <load-on-startup>0</load-on-startup>
</servlet>

NB: If you have more than one of these tomcat will call them in order
(ascending) based on the value of the load-on-startup tag's body. ok?

NB: this means that the class mail.Core must be on Tomcat's CLASSPATH,
put it in WEB-INF/classes, a jar in WEB-INF/lib or whatever.

I've found that using this along with <init-param> tags is an easy way
to configure my app.

To find out more than you've ever wanted to know about web.xml and
everything you could go read the Java Servlet Specification
(http://java.sun.com/servlet/something-or-another)

-- 
-Marco
Ring the bells that still can ring.
Forget the perfect offering.
There's a crack in everything.
It's how the light gets in.
	-Isonard Cohen