tomcat在com.opensymphony.xwork2.ActionSupport上给出classnotfoundexception,当它出现在WEB-INF / lib中时

时间:2013-12-27 22:13:24

标签: tomcat struts2

我正在尝试在tomcat中部署一个目录,该目录在 WEB-INF / lib 文件夹中包含以下与struts2相关的jar: -

commons-fileupload-1.2.2.jar
commons-logging-1.1.1.jar
freemarker-2.3.19.jar
javassist-3.11.0.GA.jar
xwork-core-2.3.8.jar
commons-lang3-3.1.jar
ognl-3.0.6.jar
struts2-core-2.3.8.jar  // and some jars containing business-logic

但是,在tomcat中部署此目录时,它会以下列方式抛出 ClassNotFoundException : -

Dec 27, 2013 4:42:27 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class
org.apache.struts2.dispatcher.ng.listener.StrutsListener
    java.lang.NoClassDefFoundError: com/opensymphony/xwork2/ActionSupport
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:788)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:447)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:270)
    ...and 26 more

    Caused by: java.lang.ClassNotFoundException: com.opensymphony.xwork2.ActionSupport
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 42 more

这真的很奇怪,因为“xwork-core-2.3.8.jar”,在WEB-INF / lib文件夹中,包含tomcat遗漏的同一个类,即com。 opensymphony.xwork2.ActionSupport。更奇怪的是,我试图在另一台计算机上部署相同的目录,并且它工作得很好。我不知道这里出了什么问题。我很感激帮助你解决这个问题。

这是我写的 web.xml : -

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
id="WebApp_ID" version="3.0">
  <display-name>KrozonaService</display-name>
  <filter>
      <filter-name>struts2</filter-name>
      <filter-class>
          org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
      </filter-class>
      <init-param>
         <param-name>actionPackages</param-name>
         <param-value>com.krozona.databaseaccess.gatewayService</param-value>
      </init-param>
      </filter>
         <filter-mapping>
           <filter-name>struts2</filter-name>
            <url-pattern>/*</url-pattern>
           </filter-mapping>
      <listener>
          <listener-class>
              org.apache.struts2.dispatcher.ng.listener.StrutsListener
           </listener-class>
      </listener>
      <welcome-file-list>
          <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
</web-app>

这里是 struts.xml : -

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

      <action name="GetTags" 
           class="com.krozona.databaseaccess.gatewayService.GetTagsAction" 
           method="execute">
           <result name="success">/HelloWorld.jsp</result>
      </action>
  </package>
</struts>

1 个答案:

答案 0 :(得分:0)

这很奇怪,但是,将相同的jar放在 TOMCAT / lib 而不是 webapp / WEB-INF / lib 中解决了这个问题。不知道为什么,但它确实有效。