配置类org.apache.struts2.tiles.StrutsTilesListener的应用程序侦听器时出错

时间:2014-04-06 07:34:19

标签: struts2 tiles

我正在尝试将Tiles3.0.3与Struts2集成,但我得到java.lang.NoClassDefFoundError and java.lang.ClassNotFoundException

这是我的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>

这是我的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>

这些是我得到的错误

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

这些是我正在使用的罐子: - commons-beanutils-1.8.2.jarcommons-digester-1.7.jarstruts2-tiles-plugin-2.2.3.1.jartiles-api-3.0.3.jartiles-compat-3.0.3.jartiles-core-3.0.3.jartiles-jsp-3.0.3.jar,tiles-servlet-3.0.3.jar

请帮帮我。

1 个答案:

答案 0 :(得分:2)

你需要在web-inf / classes中使用tile jar。

如果您的项目已启用maven,请使用以下内容:

<dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-tiles-plugin</artifactId>
    <version>2.3.16.1</version>
</dependency>

或者下载struts-tiles插件和tile插件罐子manualy