Struts 6.3.0.2项目的Mvn构建在tomcat10上部署失败

问题描述 投票:0回答:1

我使用maven archetype Blank创建了一个Struts2项目。当我执行 mvn jetty:run 时,应用程序工作正常。但是,如果我执行“mvn package”并手动部署到 Tomcat,应用程序将无法启动。如果我尝试从包含 Tomcat 10 的 eclipse IDE 中进行部署,那就是 Dito。产品目标将是 Tomcat。

struts2 过滤器似乎无法被识别。请参阅下面的两条轨迹。下面是我尝试使用管理器 GUI 在 Tomcat 中进行部署时的情况。

05-Jan-2024 09:28:44.708 INFO [http-nio-8080-exec-16] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [C:\Tomcat\apache-tomcat-10.1.17\webapps\basic_struts-0.0.1-SNAPSHOT.war]
05-Jan-2024 09:28:46.598 INFO [http-nio-8080-exec-16] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
05-Jan-2024 09:28:46.598 SEVERE [http-nio-8080-exec-16] org.apache.catalina.core.StandardContext.startInternal One or more Filters failed to start. Full details will be found in the appropriate container log file
05-Jan-2024 09:28:46.598 SEVERE [http-nio-8080-exec-16] org.apache.catalina.core.StandardContext.startInternal Context [/basic_struts-0.0.1-SNAPSHOT] startup failed due to previous errors
05-Jan-2024 09:28:46.613 INFO [http-nio-8080-exec-16] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [C:\Tomcat\apache-tomcat-10.1.17\webapps\basic_struts-0.0.1-SNAPSHOT.war] has finished in [1,905] ms
05-Jan-2024 09:28:52.532 INFO [http-nio-8080-exec-20] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
05-Jan-2024 09:28:52.547 SEVERE [http-nio-8080-exec-20] org.apache.catalina.core.StandardContext.startInternal One or more Filters failed to start. Full details will be found in the appropriate container log file
05-Jan-2024 09:28:52.547 SEVERE [http-nio-8080-exec-20] org.apache.catalina.core.StandardContext.startInternal Context [/basic_struts-0.0.1-SNAPSHOT] startup failed due to previous errors
05-Jan-2024 09:30:35.159 INFO [http-nio-8080-exec-22] org.apache.catalina.util.LifecycleBase.stop The stop() method was called on component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/basic_struts-0.0.1-SNAPSHOT]] after stop() had already been called. The second call will be ignored.
05-Jan-2024 09:30:35.703 INFO [http-nio-8080-exec-22] org.apache.catalina.startup.HostConfig.undeploy Undeploying context [/basic_struts-0.0.1-SNAPSHOT]

第二条痕迹 在 Eclipse 中工作并定位 Tomcat 部署时,控制台消息显示 struts2 过滤器无法启动。下面是 Eclipse 中的控制台消息-

Jan 05, 2024 10:48:15 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet engine: [Apache Tomcat/10.1.17]
Jan 05, 2024 10:48:17 AM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Jan 05, 2024 10:48:17 AM org.apache.catalina.core.StandardContext filterStart
SEVERE: Exception starting filter [struts2]
java.lang.NoClassDefFoundError: javax/servlet/Filter
    at java.base/java.lang.ClassLoader.defineClass1(Native Method)
    at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1013)
    at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
    at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2352)
    at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:800)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1317)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1165)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:491)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:473)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:143)
    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:243)
    at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:98)
    at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4271)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4886)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:171)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1332)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1322)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
    at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:866)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:845)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:171)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1332)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1322)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
    at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:866)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:240)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:171)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:433)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:171)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:917)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:171)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:795)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    at java.base/java.lang.reflect.Method.invoke(Method.java:578)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:347)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:478)
Caused by: java.lang.ClassNotFoundException: **javax.servlet.Filter**
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1353)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1165)
    ... 40 more

Jan 05, 2024 10:48:17 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: One or more Filters failed to start. Full details will be found in the appropriate container log file
Jan 05, 2024 10:48:17 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/basic_struts] startup failed due to previous errors
Jan 05, 2024 10:48:17 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]

您有什么建议吗?这是我尝试过的--

  1. 我确保 eclipse 构建路径在类路径上有 struts2 (6.3.0.2) 库。

  2. 我添加了一个条目,以确保在项目/属性/部署程序集中选择构建类路径下的 Struts2 lib,方法是添加一个条目并查看它被放置在 WEB-INF/lib 下

  3. 我尝试寻找最近的maven tomcat插件,但没有找到。 tomcat 8 maven插件的说明不起作用。

  4. 如果我执行 mvn package 然后尝试手动部署,在 jetty 下构建和运行的其他 Struts2 示例(Github 上)都无法在 Tomcat 下运行。

这是我的文件 --

**Web.XML**
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
         http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
  <filter>
    <filter-name>struts2</filter-name>
    <filter-class>
      org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
    </filter-class>
  </filter>

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

  <welcome-file-list>
    <welcome-file>WEB-INF/index.html</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.5//EN"
        "http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
    <constant name="struts.enable.DynamicMethodInvocation" value="false"/>
    <constant name="struts.devMode" value="true"/>
    <include file="example.xml"/>
    <package name="default" namespace="/" extends="struts-default">
        <default-action-ref name="index"/>
        <action name="index">
            <result type="redirectAction">
                <param name="actionName">HelloWorld</param>
                <param name="namespace">/example</param>
            </result>
        </action>
    </package>
</struts>

**HelloWorld.jsp**
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
    <title><s:text name="HelloWorld.message"/></title>
</head>

<body>
<h2><s:property value="message"/></h2>

<h3>Languages</h3>
<ul>
    <li>
        <s:url var="url" action="HelloWorld">
            <s:param name="request_locale">en</s:param>
            
        </s:url>
        <s:a href="%{url}">English</s:a>
    </li>
    <li>
        <s:url var="url" action="HelloWorld">
            <s:param name="request_locale">es</s:param>
        </s:url>
        <s:a href="%{url}">Espanol</s:a>
    </li>
</ul>

</body>
</html>


**Action Class HelloWorld.java**

package basic_struts.example;
import com.opensymphony.xwork2.ActionSupport;

/**
 * <code>Set welcome message.</code>
 */
public class HelloWorld extends ActionSupport {

    public String execute() throws Exception {
        setMessage(getText(MESSAGE));
        return SUCCESS;
    }

    /**
     * Provide default value for Message property.
     */
  public static final String MESSAGE = "HelloWorld.message";
   // public static final String MESSAGE = "My Test Message";

    /**
     * Field for Message property.
     */
    private String message;

    /**
     * Return Message property.
     *
     * @return Message property
     */
    public String getMessage() {
        return message;
    }

    /**
     * Set Message property.
     *
     * @param message Text to display on HelloWorld page.
     */
    public void setMessage(String message) {
        this.message = message;
    }
}
maven eclipse-plugin struts2
1个回答
0
投票

回到 Tomcat 9。Tomcat 10.1 使用 Jakarta EE 9,意思是“jakarta”包名称,而不是原始的“javax”包名称 - 这就是为什么您会收到有关 Filter 类型的运行时错误。在出现针对 Jakarta EE 9 或更高版本的较新 Struts 版本之前,您无法使用 Tomcat 10.1。

© www.soinside.com 2019 - 2024. All rights reserved.