On 23/04/2010 03:48, Godmar Back wrote: > Following up on an earlier conversation about how to obtain notification > when a WebApp is unloaded/reloaded [1], I was told that registering a > ServletContextListener is the only possibility (that is, there is no runtime > API.) > > However, registering a ServletContextListener doesn't work and leads to me > being unable to start the web application. > > To recap: I have an application with context reloadable=true. I continuously > recompile this application during development. The application starts a > worker thread I need to shut down when a newly compiled version of the > application is loaded (that is, when new versions of the .class files show > up in the WEB-INF/classes directory. > > Right now, I'm getting messages that the listener class is missing (it isn't > - it's just a new .class file after recompilation.) > > Apr 22, 2010 10:31:25 PM org.apache.catalina.loader.WebappClassLoader > modified > SEVERE: Resource > '/WEB-INF/classes/org/libx/editionbuilder/GCHelper$ShutdownListener.class' > is missing > Apr 22, 2010 10:31:25 PM org.apache.catalina.core.StandardContext reload > INFO: Reloading this Context has started > Apr 22, 2010 10:31:25 PM org.apache.catalina.core.StandardContext start > SEVERE: Error listenerStart > Apr 22, 2010 10:31:25 PM org.apache.catalina.core.StandardContext start > SEVERE: Context [/gbed] startup failed due to previous errors > > My web.xml contains: > <listener> > > <listener-class>org.libx.editionbuilder.GCHelper$ShutdownListener</listener-class> > </listener>
I think the class needs to be a top level class with a parameter free constructor. p > So - what is the correct way to register a listener that is executed when an > application is reloaded due to a recompilation? > > Does Tomcat get confused when the listener class itself is part of the > to-be-reloaded web application? > > Thanks. > > - Godmar > > > [1] See > http://mail-archives.apache.org/mod_mbox/tomcat-users/201004.mbox/%3cu2s719dced31004132122oc656c456ya25e1a4ba4d4a...@mail.gmail.com%3e > and the messages in that thread. > > ---------- Forwarded message ---------- > From: Godmar Back <god...@gmail.com> > Date: Wed, Apr 14, 2010 at 10:20 AM > Subject: Re: Q: how to obtain notification when a WebApp is > unloaded/reloaded? > To: Tomcat Users List <users@tomcat.apache.org> > > > On Wed, Apr 14, 2010 at 10:12 AM, Pid <p...@pidster.com> wrote: > >>> For instance, if you look at >>> >> http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContextListener.html >>> it says: >>> >>> "To recieve (sic) notification events, the implementation class must be >>> configured in the deployment descriptor for the web application." >> >> Web applications are largely configured by the web.xml file in >> app/WEB-INF. Servlets, listeners etc are all configured in it. >> >> > Thank you for your confirmation. I thought I was going nuts, after having > waded through various *Facade classes, hoping to find an API method I could > call at runtime. > > I have added a ServletContextListener, but it is very much a solution I > strongly dislike. The reason is that my application is layered on top of > another application (ZK), and I don't really want to touch web.xml. > 'web.xml' describes how ZK is configured to run inside Tomcat or another > J2EE server. My applications runs on top of ZK, and having to go and made > changes to the underlying deployment descriptor violates basic principles of > layering. > > It also creates a maintenance problem (unless an application can have > multiple .xml files that are combined to form a deployment descriptor). > Whenever ZK is updated, a new version of web.xml will be installed, and I > would then have to merge my <listener> declaration into the new file. > > Just out of curiosity, what is the rationale for the (apparently deliberate) > lack of an runtime API? > > - Godmar >
signature.asc
Description: OpenPGP digital signature