我在加载 jar 时遇到了一些问题。我在 Tomcat 上部署了一个 Struts2 Web 应用程序,结果出现错误:
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
我已经排除了 pom.xml
中的所有 jar 冲突,但它似乎是 Tomcat lib 中的另一个 slf4j-log4j
文件。
然后尝试把tomcat/lib中的slf4j-log4j12-1.5.8.jar去掉,重新运行war,还是报错:
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.
我在这里遗漏了什么吗?
编辑: 我已经删除了 pom.xml 中包含的冗余 servlet-api:它意外地被另一个 jar 包含了。但是在排除那个 jar 之后我得到了错误:
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
我的 Tomcat 中的 servlet-api 版本为 2.5; pom.xml 中排除的 servlet-api.jar 版本为 2.4。
最佳答案
我认为 tomcat 没有捆绑 slf4j,所以从 tomcat/lib
中删除它是正确的步骤。
那么,你不应该有servlet-api-x.jar
在 WEB-INF/lib
,因为它与 tomcat 捆绑在一起。标记为 <scope>provided</scope>
在 maven pom 中。
为确保一切都已清理干净,请调用 mvn clean
关于java - Maven 和 Tomcat 中的 Jar 冲突?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5496809/