2011-10-04 71 views
2

我使用的是struts 2.2.1和tiles 2.2.2。我做每一個步驟描述here,但我不能讓瓷磚工作...我得到,同時部署了以下錯誤我的戰爭GlassFish的3.1:Tiles與Struts2搭配使用的問題

[#|2011-10-04T08:43:28.117+0200|SEVERE|glassfish3.1|javax.enterprise.system.tools.admin.org.glassfish.deployment.admin|_ThreadID=74;_ThreadName=AutoDeployer;|Exception while invoking class com.sun.enterprise.web.WebApplication start method 
java.lang.Exception: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.IllegalArgumentException: java.lang.ClassNotFoundException: org.apache.struts2.tiles.StrutsTilesListener 
    at com.sun.enterprise.web.WebApplication.start(WebApplication.java:130) 

在我的WEB-INF/lib中我有commons- collections-3.1.jar,commons-fileupload-1.2.1.jar,struts2-core-2.2.1.jar,tiles-api-2.2.2.jar,tiles-core-2.2.2.jar,tiles-jsp- 2.2.2.jar和xwork-core-2.2.1.jar。

這是我的struts.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE struts PUBLIC 
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" 
    "http://struts.apache.org/dtds/struts-2.0.dtd"> 
<struts> 
    <constant name="struts.devMode" value="true" /> 

    <package name="basicstruts2" extends="struts-default"> 
     <interceptors> 
      <interceptor-stack name="appDefault"> 
       <interceptor-ref name="defaultStack"> 
        <param name="exception.logEnabled">true</param> 
        <param name="exception.logLevel">ERROR</param> 
       </interceptor-ref> 
      </interceptor-stack> 
     </interceptors> 

     <default-interceptor-ref name="appDefault" /> 

     <result-types> 
      <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" /> 
     </result-types> 

     <global-results> 
      <result name="exception">/jsp/exceptions/exception.jsp</result> 
      <result name="webServiceException">/jsp/exceptions/webserviceexception.jsp</result> 
     </global-results> 

     <global-exception-mappings> 
     <exception-mapping exception="java.lang.Exception" result="exception" /> 
     <exception-mapping exception="java.io.IOException" result="exception" /> 
     <exception-mapping exception="exceptions.WebServiceExceptionForStruts" 
       result="webServiceException" /> 
     </global-exception-mappings> 

     <action name="tilesTest" class="test.action.TilesTest"> 
      <result name="success" type="tiles">/welcome.tiles</result> 
     </action> 

     <action name="index"> 
      <result>/jsp/index.jsp</result> 
     </action> 

    </package> 
</struts> 

插入代碼到我的struts.xml後,我在日食出現此錯誤:

enter image description here

這是我的網頁。 xml:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 
    <display-name>Consumer</display-name> 

    <welcome-file-list> 
     <welcome-file>/jsp/index.jsp</welcome-file> 
    </welcome-file-list> 

    <filter> 
     <filter-name>struts2</filter-name> 
     <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> 
    </filter> 

    <filter-mapping> 
     <filter-name>struts2</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 

    <listener> 
     <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class> 
    </listener> 
    <context-param> 
     <param-name>tilesDefinitions</param-name> 
     <param-value>/WEB-INF/tiles.xml</param-value> 

    </context-param> 

</web-app> 

非常感謝!

回答

1

您錯過了S2 tiles插件。它在參考文章中列出。

您的第二個XML問題在IDE錯誤中有明確說明;錯誤消息中給出的元素順序不是您在XML文件中定義元素的順序。

+0

我已經添加了Struts2的瓷磚,插件-2.2.1.jar和糾正在struts.xml中的順序。 IDE錯誤消失了,但ClassDefNotFound仍然存在(現在在另一個點):[#| 2011-10-04T23:39:35.690 + 0200 | SEVERE | glassfish3.1 | org.apache.catalina.core.ContainerBase | _ThreadID = 17; _ThreadName = AutoDeployer; | ContainerBase.addChild:start: org.apache.catalina.LifecycleException:java.lang.IllegalArgumentException:java.lang.NoClassDefFoundError:org/apache/tiles/web/startup/TilesListener \t在org.apache.catalina.core.StandardContext.start(StandardContext.java:5271) – strauberry

+0

我的第一個假設是要實際檢查[tiles tiles插件使用的tiles版本](http://mvnrepository.com/artifact/ org.apache.struts/Struts2的瓷磚,插件/ 2.2.1)。這會讓我相信你是混合和匹配不兼容的版本。 –

+0

好的一個:-)依賴關係是「邪惡的一部分」。但是有很多依賴......我會看看maven ^^非常感謝您的幫助! – strauberry

0

ClassNotFoundException,看起來像缺少jar問題。你能看到正在部署在glassfish server上的戰爭中的tiles plugin jar。如果沒有檢查在你的IDE中檢查戰爭創建設置。我們在不把瓶子從自由戰爭推向戰爭時遇到了這個問題。

+0

在自動部署文件夾中的戰爭也有我所定義的所有罐子...... – strauberry

0

ClassNotFoundException總是提醒您某些引用的類/ jar已丟失。確保你有瓷磚所需的所有基本罐子。

在我的情況下,我在我的struts2應用程序中使用這些jar(除了struts2 jars)來測試演示磁貼項目。

  • 公地的BeanUtils-1.7.0.jar
  • 公共沼氣池-2.0.jar
  • 共享記錄-1.1.1.jar
  • 共享記錄-API-1.1.jar
  • OGNL-3.0.1.jar
  • SLF4J-API-1.6.2.jar
  • SLF4J-簡單1.6.2.jar
  • Struts2的瓷磚 - 插件 - 2.2.3.1.jar
  • 瓷磚-API-2.2.2.jar
  • 瓷磚-COMPAT-2.2.2.jar
  • 瓷磚核-2.2.2.jar
  • 瓷磚-JSP-2.2.2.jar
  • 瓷磚-的servlet-2.2.2.jar
  • 瓷磚,模板2.2.2.jar

好運。

問候, 阿米爾·阿里·