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?
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.
"privilege" comes from the Latin words for "private" and "law" (legal) and dates to feudal times. To "claim privilege" meant that you were above the laws that applied to the common people.
posted 6 years ago
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.