• Post Reply Bookmark Topic Watch Topic
  • New Topic

Default methods executed by Jetty/Tomcat while loading/reloading the .war

 
Faraz Ka
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have created a dynamic web Application for RESTful web Service using JAX-RS Jersey implementation and deployed as a .war file in a container ( works fine in both Tomcat and Jetty)
Next, the other requirement is when the web container loads the .war, I need one method to be called ( to check the location of 'myTemp' folder for the files in the same host machine and copy the files from within the .war file to the folder 'myTemp')

So, just wanted to know if there is a way where Tomcat or Jetty executes some method on its own while loading/reloading the .war file OR any out of the box support provided by the container?

Please help.

Regards,
FK
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ServletContextListener
 
Faraz Ka
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear. I tried ServletContextListener and it worked for me for Tomcat.
Not sure if the same logic can be applied for Jetty. Please confirm if it can be used with Jetty as well.

Thanks again.
Faraz
 
Tim Holloway
Bartender
Posts: 18408
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ServletContextListener is a J2EE standard service that is employed whenever a webapp goes up or down. So for Jetty not to act just like Tomcat, Jetty would have to update the WAR without stopping it. Which is a questionable thing to do.

Beyond that, if you are creating files within the WAR, you are violating the J2EE standards and playing with fire. DON'T DO IT. Yes, I know it works in a lot of different versions and brands of servers when certain options are in effect. But just because you can do something, doesn't mean it's safe to do if the standard doesn't support it. And this is very definitely unsafe. I think in fact, you're trying to kludge around that very lack of safety.

You would be far better off if you designated a directory that's totally external to both your war and the webapp server itself to hold mutable files in.
 
Faraz Ka
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tim for the valuable information.
What I am trying out is as follows

In my Dynamic Web Application I am creating a folder and place some files ( set of xmls and .ini files) and then export the web Application as a war file to be run on Jetty.
When its getting loaded in Jetty, the ServletContextListener ( through some custom code) will push these files ( xml and .ini) to some other location in the main OS directory ( lets say C:\Users\Administrator) from where it is picked by other agent ( REST in my case)

Please suggest if you still see challenge in this design/implementation.

Regards,
Faraz
 
Tim Holloway
Bartender
Posts: 18408
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds good to me. It's what I would do when I wasn't using an OS installer to deploy my WARS.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!