0

I want my java web application run a program automatically when i start or deploy the program in glassfish server. My web application need to run a mail program inside glassfish when just deployed.

user1504940
  • 175
  • 4
  • 14

2 Answers2

0

You can just set some flag type attribute in your database and change the value after run the program.

memo
  • 441
  • 2
  • 6
0

You can set up a servlet to run on application startup, or possibly use the @Singleton annotation, depending on whether you want EJB involved. Or if you're using Spring, there are more ways. You could give some more background for better answers.

What does the servlet <load-on-startup> value signify

http://java.sun.com/developer/technicalArticles/JavaEE/JavaEE6Overview_Part3.html#singles

Community
  • 1
  • 1
Jim
  • 3,476
  • 4
  • 23
  • 33
  • I am using JSF. How can i do that by JSF. i just need to run a single java program automatically when web application run. – user1504940 Jul 13 '12 at 15:38
  • Sorry I don't know JSF, but I imagine it starts with some kind of servlet. But if I google "jsf startup bean" I find things like: http://jfindings.blogspot.com/2009/04/creating-startup-listener-in-jsf.html where you can do things with ContextLoaderListener, ServletContextListener, web.xml, `@Component`, and `@Scope` to get the behavior I'm guessing you're looking for. Sounds complicated. – Jim Jul 13 '12 at 15:49
  • Thanks Jim. I just want that when i start my web application it will send email automatically at specified time from database. i wrote the mail class but i need to run the mail class internally as i run the web application. – user1504940 Jul 13 '12 at 16:09