2

I'm having some trouble with jar loading. I deployed a Struts2 web application on Tomcat, and it resulted in error:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:....../Tomcat%206.0/lib/slf4j-log4j12-1.5.8.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:....../Tomcat%206.0/webapps/Timesheet/WEB-INF/lib/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
2011-03-31 14:33:48,302 DEBUG com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadConfigurationFiles:748 - Loading action configurations from: struts-default.xml
2011-03-31 14:33:50,592 DEBUG com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadConfigurationFiles:832 - Loaded action configuration from: struts-default.xml
...
2011-03-31 14:33:50,809 DEBUG com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register:202 - Loaded type:com.opensymphony.xwork2.util.XWorkConverter name:struts impl:com.opensymphony
.xwork2.util.AnnotationXWorkConverter
Mar 31, 2011 2:33:50 PM org.apache.catalina.core.StandardContext start
SEVERE: Error filterStart
Mar 31, 2011 2:33:50 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/Timesheet] startup failed due to previous errors

I have excluded all jar-conflicts in pom.xml, but it seems to be another slf4j-log4j file in Tomcat lib.

Then I tried to remove the slf4j-log4j12-1.5.8.jar in Tomcat/lib and re-run the war again, but still got another error:

Mar 31, 2011 2:44:51 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(...\Tomcat 6.0\webapps\Timesheet\WEB-INF\lib\servlet-api-2.4.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class:
javax/servlet/Servlet.class
... // Struts file still loaded here, but another Error filterStart: the same as above.

Does I miss anything here?

EDIT: I have remove the redundant servlet-api included in pom.xml: it is accidentally included by another jar. But after excluding that jar I got the error:

Mar 31, 2011 4:11:19 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(...\Tomcat 6.0\webapps\Timesheet\WEB-INF\lib\servlet-api-2.4.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class:
javax/servlet/Servlet.class
2011-03-31 16:11:20,234 DEBUG com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadConfigurationFiles:748 - Loading action configurations from: struts-default.xml
2011-03-31 16:11:21,028 DEBUG com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadConfigurationFiles:832 - Loaded action configuration from: struts-default.xml

My servlet-api in my Tomcat has version 2.5; the excluded servlet-api.jar in pom.xml has version 2.4.

Hoàng Long
  • 10,746
  • 20
  • 75
  • 124

2 Answers2

7

I don't think tomcat comes with slf4j bundled, so removing it from tomcat/lib is a proper step.

Then, you should not have servlet-api-x.jar in WEB-INF/lib, because it bundled with tomcat. Mark it as <scope>provided</scope> in the maven pom.

To make sure everything is cleaned-up call mvn clean

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
2

It seems that something is pulling in servlet-api-2.4.jar which is not supposed to be deployed as part of a webapp. If you have servlet-api as a dependency in your project, ensure it has a scope of provided. This tells maven to use it for compilation but not for packaging. (see this Maven FAQ entry and Introduction to the Dependency Mechanism).

However, servlet-api might also be being pulled in because it is referenced transitively from one of your project dependencies. If this is the case, trying running:

mvn dependency:tree

to print out a list of transitive dependencies and where they are coming from. In the output, search for the servlet-api dependency with a non-provided scope. You can then remove the offender by adding an exclude to its ancestor dependency in your POM.

prunge
  • 22,460
  • 3
  • 73
  • 80
  • @Bozho: You're right, but after I exclude the servlet-api, the problem still persists. I think that if Tomcat provide the jar, I don't need to include it in pom.xml. Is that right? – Hoàng Long Mar 31 '11 at 09:25
  • @Hoàng Long: You will still need servlet-api for compilation in Maven, otherwise anything referring to the base Servlet/JSP classes (HttpServlet, ServletRequest, etc.) wont be found when compiling. It still needs to be included, but with 'provided' scope. – prunge Apr 01 '11 at 01:55
  • sorry, but I can't find any way to do this. How can I specify a jar as provided, while it's pulled by a transitive dependency? – Hoàng Long Apr 01 '11 at 08:03