You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mike Peremsky <mp...@yahoo.com> on 2007/04/16 05:35:10 UTC

Unable to get a Listener running

  To whom it may concern:
   
   
  I am trying to implement a Listener in my Java application using Tomcat 5.5. My class implements the LifecycleListener (as shown below)
   
  public class SingletonLoader implements LifecycleListener {
   
     public void lifecycleEvent(LifecycleEvent event) {
      System.out.println("***  event type: " + event.getType());
   }
}
   
  When I try to execute the statrup.bat file I get the following exception in my log file:
   
   
  INFO: org.apache.webapp.balancer.BalancerFilter: init(): ruleChain: [org.apache.webapp.balancer.RuleChain: [org.apache.webapp.balancer.rules.URLStringMatchRule: Target string: News / Redirect URL: http://www.cnn.com], [org.apache.webapp.balancer.rules.RequestParameterRule: Target param name: paramName / Target param value: paramValue / Redirect URL: http://www.yahoo.com], [org.apache.webapp.balancer.rules.AcceptEverythingRule: Redirect URL: http://jakarta.apache.org]]
Apr 15, 2007 10:53:25 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Error configuring application listener of class com.sf.listener.SingletonLoader
java.lang.NoClassDefFoundError: org/apache/catalina/LifecycleListener
 at java.lang.ClassLoader.defineClass1(Native Method)
 at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
 at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
 at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1847)
 at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:873)
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1326)
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1205)
...
  Apr 15, 2007 10:53:25 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Skipped installing application listeners due to previous error(s)

   
  I build the code using NetBeans and have the %CATALINA_HOME%\server\lib\catalina.jar file included in the classpath to find the org.apache.catalina.LifecycleListener. I noticed that this jar file is not in the CLASSPATH in startup. If I modified the setclasspath.bat file directly to add the catalina.jar to the CLASSPATH, but if I do that then the tomcat server does not start up at all. It flashes a few lines on the screen then disappears. I do not know what the messages read.
   
  I have tried scouring the apache.org site and google, but I cannot find a resolution to this issue. I also tried to add the jar to the server.loader in the catalina.properties file, which had no affect wither.
   
  Any help would be appreciated.
   
  Michael Peremsky

       
---------------------------------
Ahhh...imagining that irresistible "new car" smell?
 Check outnew cars at Yahoo! Autos.

Re: Unable to get a Listener running

Posted by Rashmi Rubdi <ra...@gmail.com>.
On 4/16/07, Mike Peremsky <mp...@yahoo.com> wrote:
> From the control panel. If I go to the system properties and look at the environment variables I have the following: (I do not have a JRE_HOME defined)
>
>   CATALINA_HOME=c:\apache-tomcat
> JAVA_HOME=c:\jdk1.5.0
Path=C:\jdk1.5.0\bin;%ANT_HOME%\bin

The above looks correct, but the PATH could still be improved so
change the above PATH

to PATH=%JAVA_HOME%/bin;%ANT_HOME%/bin;%CATALINA_HOME%/bin

>
>   There is a CLASSPATH variable set as:
>
>   .;C:\Program Files\Java\jre1.5.0_11\lib\ext\QTJava.zip
>

Temporarily unset the CLASSPATH (system environment variable).

>
>   My jdk is installed to c:\jdk1.5.0 and my tomcat is installed at c:\apache-tomcat as is
> stated in the environment variables.

This is fine.

>
>   I did a fresh install of Tomcat 5.5.23 (I had not had it installed previously). Everything
> was working fins until I tried to create a listener. My code is deployed to
> c:\apache-tomcat\webapps\fs with all class files in WEB-INF\classes.

Each listener you write must also be defined in the deployment
descriptor \WEB-INF\web.xml , for example:

    <listener>
        <listener-class>any.package.SingletonLoader</listener-class>
    </listener>

    <listener>
        <listener-class>any.package.ApplicationWatch</listener-class>
    </listener>

and so on...

> I also have 1 jar file that I have utility classes in :\apache-tomcat\common\lib\mvpUtils.jar.
>
>   If the listener is in the catalina.jar file,

Actually the listener doesn't need to be in catalina.jar at all , it
can be anywhere under your project's /WEB-INF/classes/ folder also.

The reason why the code in the LifecycleListener isn't being called is
because an event that is supposed to be captured by the
LifecycleListener didn't occur .....

According to the definition
http://tomcat.apache.org/tomcat-5.0-doc/catalina/docs/api/org/apache/catalina/LifecycleListener.html
"Interface defining a listener for significant events (including
"component start" and "component stop" generated by a component that
implements the Lifecycle interface."

I tried implementing the ServletContextListener, and it was able to
capture the Tomcat start and shutdown events.

May be you could try one of the sub-interfaces such as:
http://tomcat.apache.org/tomcat-5.0-doc/catalina/docs/api/org/apache/catalina/mbeans/ServerLifecycleListener.html

> and the jar file is in the c:\apache-tomcat\server\lib\ directory. Which, as you say, should > already include any jars in that directory, how could it fail finding the class?

It is not failing in finding the class (the NoClassDefinitionFound
error can be solved normally by unsetting the system classpath), as
long as the class is under the project's WEB-INF/classes folder , it
will find the class. The real question here is why didn't capture a
particular event that you expect it to capture.

What event are you expecting the LifecycleListener to capture?

-Rashmi

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Unable to get a Listener running

Posted by Mike Peremsky <mp...@yahoo.com>.
>From the control panel. If I go to the system properties and look at the environment variables I have the following: (I do not have a JRE_HOME defined)
   
  CATALINA_HOME=c:\apache-tomcat
JAVA_HOME=c:\jdk1.5.0  Path=C:\jdk1.5.0\bin;%ANT_HOME%\bin
   
  There is a CLASSPATH variable set as: 
   
  .;C:\Program Files\Java\jre1.5.0_11\lib\ext\QTJava.zip
   
   
  My jdk is installed to c:\jdk1.5.0 and my tomcat is installed at c:\apache-tomcat as is stated in the environment variables.
   
  I did a fresh install of Tomcat 5.5.23 (I had not had it installed previously). Everything was working fins until I tried to create a listener. My code is deployed to c:\apache-tomcat\webapps\fs with all class files in WEB-INF\classes. I also have 1 jar file that I have utility classes in c:\apache-tomcat\common\lib\mvpUtils.jar.
   
  If the listener is in the catalina.jar file, and the jar file is in the c:\apache-tomcat\server\lib\ directory. Which, as you say, should already include any jars in that directory, how could it fail finding the class?
  
Rashmi Rubdi <ra...@gmail.com> wrote:
  I tried your code, it didn't capture any event but Tomcat didn't throw
any errors.

Typically the error > java.lang.NoClassDefFoundError occurs when a
system wide classpath is incorrectly set or partially set.

Actually there's no need to set a system wide classpath. Tomcat 5.5.x
auto detects it.

The only things you need to set are CATALINA_HOME
and JAVA_HOME or JRE_HOME , don't add any of Tomcat's JAR files in the
system classpath, that should solve the Tomcat startup error, if you
are using a fresh startup.bat (that comes with a fresh Tomcat
download).

-Rashmi

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org



       
---------------------------------
Ahhh...imagining that irresistible "new car" smell?
 Check outnew cars at Yahoo! Autos.

Re: Unable to get a Listener running

Posted by Rashmi Rubdi <ra...@gmail.com>.
I tried your code, it didn't capture any event but Tomcat didn't throw
any errors.

Typically the error > java.lang.NoClassDefFoundError occurs when a
system wide classpath is incorrectly set or partially set.

Actually there's no need to set a system wide classpath. Tomcat 5.5.x
auto detects it.

The only things you need to set are CATALINA_HOME
and JAVA_HOME or JRE_HOME , don't add any of Tomcat's JAR files in the
system classpath, that should solve the Tomcat startup error, if you
are using a fresh startup.bat (that comes with a fresh Tomcat
download).

-Rashmi

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org