You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Sebastian Biedermann <bi...@seceng.informatik.tu-darmstadt.de> on 2011/04/07 14:48:21 UTC
Tomcat LifecycleListener
Dear List,
I want to programm an Eventlistener for the tomcat6 Server that gives
me an event when a war-file ist started.
So I added a line to the server.xml:
<Server>
[...]
<ListenerclassName="TomcatListener"/>
[...]
</Server>
And I have this little Java example code here which I put in
/usr/share/tomcat6/lib/TomcatListener.java :
import org.apache.catalina.Lifecycle;
import org.apache.catalina.LifecycleEvent;
import org.apache.catalina.LifecycleListener;
public class TomcatListener implements LifecycleListener {
public void lifecycleEvent(LifecycleEvent event) {
if(event.getType().equals(Lifecycle.BEFORE_START_EVENT)) {
// do something before Tomcat starts
}
else if (event.getType().equals(Lifecycle.AFTER_STOP_EVENT)) {
// so something after Tomcat shut down
}
}
}
But unfortunately the tomcat server is not starting anymore, the logfile says:
Caused by: java.lang.ClassNotFoundException: TomcatListener
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at org.apache.tomcat.util.digester.ObjectCreateRule.begin(ObjectCreateRule.java:205)
at org.apache.tomcat.util.digester.Rule.begin(Rule.java:153)
at org.apache.tomcat.util.digester.Digester.startElement(Digester.java:1356)
... 20 more
07.04.2011 14:12:09 org.apache.catalina.startup.Catalina start
FATAL: Cannot start server. Server instance is not configured.
Maybe that´s stupid from my side, but I dont know where to put the java or
what´s going wrong there. Do I have to create a .jar?
How can i get this to work?
Thanks for help
Sebastian
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Tomcat LifecycleListener
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Sebastian Biedermann [mailto:biedermann@seceng.informatik.tu-darmstadt.de]
> Subject: Tomcat LifecycleListener
> I want to programm an Eventlistener for the tomcat6 Server
> that gives me an event when a war-file ist started.
Be precise: tell us the *exact* Tomcat version (there are ~25 releases of Tomcat 6), along with the JDK/JRE you're using, and the platform you're running on.
> So I added a line to the server.xml:
> <Server>
> [...]
> <ListenerclassName="TomcatListener"/>
> [...]
> </Server>
You're missing a space between Listener and className.
> And I have this little Java example code here which I put in
> /usr/share/tomcat6/lib/TomcatListener.java :
.java != .class
What do you expect Tomcat to do with source code? You need to compile your .java code into a class file.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
Re: Tomcat LifecycleListener
Posted by André Warnier <aw...@ice-sa.com>.
Sebastian Biedermann wrote:
> Dear List,
>
> I want to programm an Eventlistener for the tomcat6 Server that gives
> me an event when a war-file ist started.
>
> So I added a line to the server.xml:
>
> <Server>
> [...]
> <ListenerclassName="TomcatListener"/>
> [...]
> </Server>
>
>
> And I have this little Java example code here which I put in
> /usr/share/tomcat6/lib/TomcatListener.java :
>
> import org.apache.catalina.Lifecycle;
> import org.apache.catalina.LifecycleEvent;
> import org.apache.catalina.LifecycleListener;
>
> public class TomcatListener implements LifecycleListener {
> public void lifecycleEvent(LifecycleEvent event) {
> if(event.getType().equals(Lifecycle.BEFORE_START_EVENT)) {
> // do something before Tomcat starts
> }
> else if (event.getType().equals(Lifecycle.AFTER_STOP_EVENT)) {
> // so something after Tomcat shut down
> }
> }
> }
>
>
> But unfortunately the tomcat server is not starting anymore, the logfile
> says:
>
> Caused by: java.lang.ClassNotFoundException: TomcatListener
> at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
> at
> org.apache.tomcat.util.digester.ObjectCreateRule.begin(ObjectCreateRule.java:205)
>
> at org.apache.tomcat.util.digester.Rule.begin(Rule.java:153)
> at
> org.apache.tomcat.util.digester.Digester.startElement(Digester.java:1356)
> ... 20 more
> 07.04.2011 14:12:09 org.apache.catalina.startup.Catalina start
> FATAL: Cannot start server. Server instance is not configured.
>
>
> Maybe that´s stupid from my side, but I dont know where to put the java or
> what´s going wrong there. Do I have to create a .jar?
>
> How can i get this to work?
>
You may need to compile that and make it a .class, no ?
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org