问题
I am trying to integrate Tiles3.0.3
with Struts2, but I am getting java.lang.NoClassDefFoundError and java.lang.ClassNotFoundException
.
Here is my web.xml
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<context-param>
<param-name>
org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG
</param-name>
<param-value>
/WEB-INF/tiles.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.apache.struts2.tiles.StrutsTilesListener
</listener-class>
</listener>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>example/HelloWorld.jsp</welcome-file>
</welcome-file-list>
</web-app>
And here is my tiles.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<definition name="baseLayout" template="/baseLayout.jsp">
<put-attribute name="title" value="Template"/>
<put-attribute name="banner" value="/banner.jsp"/>
<put-attribute name="menu" value="/menu.jsp"/>
<put-attribute name="body" value="/body.jsp"/>
<put-attribute name="footer" value="/footer.jsp"/>
</definition>
<definition name="tiger" extends="baseLayout">
<put-attribute name="title" value="Tiger"/>
<put-attribute name="body" value="/tiger.jsp"/>
</definition>
<definition name="lion" extends="baseLayout">
<put-attribute name="title" value="Lion"/>
<put-attribute name="body" value="/lion.jsp"/>
</definition>
</tiles-definitions>
And these are the errors I am getting
SEVERE: Error configuring application listener of class org.apache.struts2.tiles.StrutsTilesListener
java.lang.NoClassDefFoundError: org/apache/tiles/web/startup/TilesListener
Caused by: java.lang.ClassNotFoundException: org.apache.tiles.web.startup.TilesListener
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
... 52 more
And these are the jars which I am using :-
commons-beanutils-1.8.2.jar
,commons-digester-1.7.jar
,struts2-tiles-plugin-2.2.3.1.jar
,
tiles-api-3.0.3.jar
,tiles-compat-3.0.3.jar
, tiles-core-3.0.3.jar
, tiles-jsp-3.0.3.jar,tiles-servlet-3.0.3.jar
Please help me out.
回答1:
You need to have tiles jar in your web-inf/classes.
If your project is maven enabled use below:
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-tiles-plugin</artifactId>
<version>2.3.16.1</version>
</dependency>
Or download struts-tiles plugin and tiles plugin jars manualy
来源:https://stackoverflow.com/questions/22891212/error-configuring-application-listener-of-class-org-apache-struts2-tiles-strutst