maven Struts 6.3.0.2项目的Mvn构建无法在tomcat10上部署

ca1c2owp  于 11个月前  发布在  Maven
关注(0)|答案(1)|浏览(109)

我使用maven archetype blank创建了一个Struts2项目。当我执行mvn jetty:run时,应用程序工作正常。但是,如果我执行“mvn package”并手动部署到Tomcat,应用程序将无法启动。如果我尝试从Eclipse IDE中部署Tomcat 10,则会出现Dito。Prod目标将是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 filter启动失败,下面是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)库。
1.我添加了一个条目,以确保在Project/Properties/Deployment Assembly中选择构建类路径下的Struts2 lib,方法是添加一个条目,并查看它被放置在WEB-INF/lib下
1.我试图寻找一个最近的tomcat插件为maven,但没有找到任何。说明tomcat 8 maven插件不工作。
1.在jetty下构建和运行的其他Struts2示例(在Github上)都不能在Tomcat下运行,如果我做mvn包,然后尝试手动部署。
这是我的文件

**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;
    }
}

vpfxa7rd

vpfxa7rd1#

回到Tomcat 9。Tomcat 10.1使用Jakarta EE 9,这意味着“jakarta”包名,而不是原始的“javax”包名--这就是为什么您会得到关于Filter类型的运行时错误。直到有针对Jakarta EE 9或更高版本的更新的Struts版本,您才能使用Tomcat 10.1。

相关问题