On 23/02/2010 18:00, STEINER Stephan wrote:
Hi
I need to launch an initialization procedure as soon as my web
application is deployed on Tomcat (working on a 6.0.20).
As per the documentation, I can define a LifecycleListener in my
context.xml file for the webapp in question. However, the documentation
says that it needs to be packed as a jar and be copied to
$CATALINA_HOME/lib. And that's where I have my catch 22.. my
implementation of LicecycleListener needs access to objects defined in
the webapp - so I figure I have to deploy basically the entire solution
to $CATALINA_HOME/lib (which can be problematic if you run different
webapps making use of different versions of the same lib), then go hack
the build file so that it won't package my libs with the webapp anymore.
>
Am I misunderstanding something here?
Yes.
> Shouldn't there be a deployment
way where I can keep the webapp self-contained? Or how can I get my
LifeCycleListener which I have to deploy outside my webapp to gain
access to the set of classes and libs that are part of the webapp?
You can't.
In other words.. if mynamespace.MyLifeCycleListener is located in
$CATALINA_HOME/lib/CustomMyLifeCycleListener.jar, how will it have
access to libs and classes located in
$CATALINA_HOME/webapps/MyebApp/WEB-INF/lib (or
..../WEB-INF/classes/mynamespace)?
It won't.
After writing these lines I figured I'd go ahead and test a little.. so
I created two libs
The Launcher Lib (launcherlib.jar) to be placed in $CATALINA_HOME/lib
The webapp lib (webapp-lib.jar) (which is used by both the launcher lib
and the webapp lib)
And the webapp itself (webapp.war)
Netbeans automatically adds a copy of the webapp lib to it.
So I first copied the launcher lib including the launcher lib's own lib
dir (containing catalina.jar and webapp-lib.jar) to the tomcat lib
directory.
Then I deployed the webapp.. and it worked out just fine.
Really? ...
In the launcher app I initialize a singleton object in the webapp lib,
and then dump the fact that the initialization has been done to the
console (system.out.println). Looking at the Tomcat logs I see that this
is being done properly each time the webapp is being started.
However, if I get the same singleton object from the webapp and query
its initialization state, it tells me it is not initialized.. so
indicating that the two instances of the webapp lib run completely
separate.
... no, not fine.
So I went ahead and changed the manifest file of the launcher lib to
reference the deployed webapp lib jar file and removed the reference to
catalina.jar (it's in the same directory so it shouldn't matter).
Madness.
Stopped and restarted the webapp.. the launcher lib still does its thing
just fine, but then accessing the webapp it still tells me the singleton
is not initialized.. so it's not a matter of where to put the files, but
even though the launcher lib is referenced in the context of the webapp,
it seems to run under a separate context and that's a problem - I need
the LifeCycleListener to initialize something that can then be used by
the webapp (I figure that's the main point to have a LifeCycleListener
for a specific webapp).. so how can I get the launcher lib and the
webapp to share their state?
As above, you're using the wrong Listener type. LifecycleListener is an
interface from org.apache.catalina and is not part of the Servlet Spec.
You need:
javax.servlet.ServletContextListener
p
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org