views:

138

answers:

2

I build a REST web service (using JAX-RS, Spring, Spring JMS, and ActiveMQ). I'm surprised that when I deploy it to Tomcat 5.5.23 I get an exception that JSF jars are required?!

Error configuring application listener of class org.apache.myfaces.webapp.StartupServletContextListener
java.lang.ClassNotFoundException: org.apache.myfaces.webapp.StartupServletContextListener
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1359)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1205)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3712)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4216)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760)

The web service was working fine until I added log4j functionality in different classes, here's my log4j.properties file (I placed it in WEB-INF/classes):

log4j.rootCategory=INFO, S

log4j.logger.com.dappit.Dapper.parser=ERROR
log4j.logger.org.w3c.tidy=FATAL

#------------------------------------------------------------------------------
#
#  The following properties configure the console (stdout) appender.
#  See http://logging.apache.org/log4j/docs/api/index.html for details.
#
#------------------------------------------------------------------------------
log4j.appender.S = org.apache.log4j.ConsoleAppender
log4j.appender.S.layout = org.apache.log4j.PatternLayout
log4j.appender.S.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %c{1} [%p] %m%n

Any idea how to resolve this?

+2  A: 

I would expect to see this if you have a reference to org.apache.myfaces.webapp.StartupServletContextListener in your web.xml, like:

<listener>
     <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>

Can you verify that there is no such element?

Brabster
I had it removed, but i'm still getting:log4j:WARN No appenders could be found for logger (org.apache.commons.digester.Digester.sax).log4j:WARN Please initialize the log4j system properly.Aug 17, 2010 12:43:02 PM org.apache.catalina.core.StandardContext startSEVERE: Error listenerStart
wsb3383
Did you add your log4j.properties file back? Do you have the log4j jar WEB-INF/lib?
Brabster
yes I did add the .properties file back, but I don't have the log4j jar in my app's web-inf because I noticed there's a log4j-1.2.8.jar under TOMCAT_HOME/shared/lib. Do I need to add it to my WEB-INF folder?
wsb3383
Give it a try - I have a faint recollection of having problems with log4j unless the jar was actually in the webapp's WEB-INF/lib folder on Tomcat.
Brabster
I did, but now i'm getting:Error configuring application listener of class org.apache.myfaces.webapp.StartupServletContextListenerIf I add all the JSF/JSTL jars that MyEclipse referenced on my development machine, I get this exception:Error configuring application listener of class com.sun.faces.config.ConfigureListenerjava.lang.NoClassDefFoundError: javax/el/ExpressionFactoryI just don't get it, why is JSF being used?
wsb3383
If you are using MyEclipse, did you do the 'Add JSF capabilities...' thing described here http://www.myeclipseide.com/documentation/quickstarts/jsf/? Sounds a little like the IDE might doing things behind the scenes
Brabster
It indeed look much like that you've either accidently or unawarely added JSF (Faces) facets yourself while creating MyEclipse web project. Just don't do that :) Rightclick project, check Project Facets and uncheck the JSF/Faces ones (and if necessary manually remove the autogenerated JSF related entries from `web.xml`).
BalusC
+1  A: 

Sounds like a classloader hierarchy issue. You should enclose log4j in your WAR file, not put it in the shared libraries of Tomcat.

Also, I had some problems with Tomcat 5.5 that was fixed in Tomcat 6.0. You may want to consider upgrading.

Thorbjørn Ravn Andersen
It was some kind of class conlfict issue:MyEclipse automatically placed the JSTL and JSF jars in my lib path, in addition I noticed that there's a class "Logger" in JSTL (org.apache.taglibs.standard.lang.jstl.Logger), once I declared my logger classes using the full apache log4j package name (org.apache.log4j.Logger) it worked!!
wsb3383