Spring 引导 + Tomcat 嵌入式 + Struts 2 - JSP 未被调用
Spring Boot + Tomcat Embedded + Struts 2 - JSP are not invoked
我正在尝试将具有 spring 引导和 struts 2(struts.xml 文件)的 Web 应用程序从 Jboss 7.1.1 迁移到 tomcat 嵌入。
现在,我的配置是这样的:
Application.java
@SpringBootApplication()
@ServletComponentScan()
public class Application extends JbossDefaultPropertiesInitializer {
public static void main(String[] args) {
configureApplication(new SpringApplicationBuilder()).run(args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
setRegisterErrorPageFilter(false);
return configureApplication(builder);
}
private static SpringApplicationBuilder configureApplication(SpringApplicationBuilder builder) {
builder.initializers(new DefaultPropertiesInitializer());
return builder.sources(Application.class);
}
}
pom.xml
<resources>
<resource>
<directory>src/main/webapp</directory>
<targetPath>/static</targetPath>
<excludes>
<exclude>**/*.jsp</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/webapp</directory>
<targetPath>/WEB-INF/jsp</targetPath>
<includes>
<include>**/*.jsp</include>
</includes>
</resource>
</resources>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.6.RELEASE</version>
<configuration>
<mainClass>com.myapplication.Application</mainClass>
<executable>true</executable>
<layout>WAR</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
struts.devMode=true
每个过滤器、servlet 和侦听器都从 web.xml 迁移到@WebFilter、@WebListener 和@WebServlets。
当我开始 tomcat 时一切似乎都正常,我能够获得一些静态资源,如 html、css 和 js。
当我调用某些 struts 页面时,如 http://localhost:8080/myapplication/login.go,一切正常,过滤器和 servlet 被调用,我的操作被调用,但是当操作 returns "success" 调用“/myapplication/jsp/login.jsp”它不呈现。 jsp 文件未被调用或存在一些错误,我在控制台中什么也没有得到。
我的操作调用 jsp 页面之前的日志:
2017-11-28 13:03:19.881 INFO 7376 --- [nio-8080-exec-3] c.o.x.c.p.XmlConfigurationProvider : Parsing configuration file [struts-default.xml]
2017-11-28 13:03:19.933 WARN 7376 --- [nio-8080-exec-3] com.opensymphony.xwork2.util.DomHelper : Local DTD is missing for publicID: -//Apache Software Foundation//DTD Struts Configuration 2.5//EN - defined mappings: {-//Apache Struts//XWork 1.1.1//EN=xwork-1.1.1.dtd, -//Apache Software Foundation//DTD Struts Configuration 2.0//EN=struts-2.0.dtd, -//Apache Struts//XWork 1.0//EN=xwork-1.0.dtd, -//Apache Software Foundation//DTD Struts Configuration 2.1//EN=struts-2.1.dtd, -//Apache Struts//XWork 1.1//EN=xwork-1.1.dtd, -//Apache Struts//XWork 2.1.3//EN=xwork-2.1.3.dtd, -//Apache Software Foundation//DTD Struts Configuration 2.3//EN=struts-2.3.dtd, -//Apache Struts//XWork 2.0//EN=xwork-2.0.dtd, -//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN=struts-2.1.7.dtd, -//Apache Struts//XWork 2.1//EN=xwork-2.1.dtd, -//Apache Struts//XWork 2.3//EN=xwork-2.3.dtd}
2017-11-28 13:03:20.220 INFO 7376 --- [nio-8080-exec-3] c.o.x.c.p.XmlConfigurationProvider : Parsing configuration file [struts-plugin.xml]
2017-11-28 13:03:20.301 INFO 7376 --- [nio-8080-exec-3] c.o.x.c.p.XmlConfigurationProvider : Parsing configuration file [struts.xml]
2017-11-28 13:03:20.304 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (spring) for (com.opensymphony.xwork2.ObjectFactory)
2017-11-28 13:03:20.304 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.factory.ActionFactory)
2017-11-28 13:03:20.304 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.factory.ResultFactory)
2017-11-28 13:03:20.304 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.factory.ConverterFactory)
2017-11-28 13:03:20.304 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.factory.InterceptorFactory)
2017-11-28 13:03:20.304 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.factory.ValidatorFactory)
2017-11-28 13:03:20.304 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.factory.UnknownHandlerFactory)
2017-11-28 13:03:20.304 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.FileManagerFactory)
2017-11-28 13:03:20.305 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.XWorkConverter)
2017-11-28 13:03:20.305 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.CollectionConverter)
2017-11-28 13:03:20.305 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.ArrayConverter)
2017-11-28 13:03:20.305 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.DateConverter)
2017-11-28 13:03:20.305 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.NumberConverter)
2017-11-28 13:03:20.305 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.StringConverter)
2017-11-28 13:03:20.305 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.conversion.ConversionPropertiesProcessor)
2017-11-28 13:03:20.305 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.conversion.ConversionFileProcessor)
2017-11-28 13:03:20.305 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.conversion.ConversionAnnotationProcessor)
2017-11-28 13:03:20.305 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.conversion.TypeConverterCreator)
2017-11-28 13:03:20.306 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.conversion.TypeConverterHolder)
2017-11-28 13:03:20.306 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.TextProvider)
2017-11-28 13:03:20.306 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.LocaleProvider)
2017-11-28 13:03:20.306 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.ActionProxyFactory)
2017-11-28 13:03:20.306 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.conversion.ObjectTypeDeterminer)
2017-11-28 13:03:20.306 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (org.apache.struts2.dispatcher.mapper.ActionMapper)
2017-11-28 13:03:20.306 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (jakarta) for (org.apache.struts2.dispatcher.multipart.MultiPartRequest)
2017-11-28 13:03:20.306 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (org.apache.struts2.views.freemarker.FreemarkerManager)
2017-11-28 13:03:20.306 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (org.apache.struts2.views.velocity.VelocityManager)
2017-11-28 13:03:20.306 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (org.apache.struts2.components.UrlRenderer)
2017-11-28 13:03:20.306 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.validator.ActionValidatorManager)
2017-11-28 13:03:20.307 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.util.ValueStackFactory)
2017-11-28 13:03:20.307 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.util.reflection.ReflectionProvider)
2017-11-28 13:03:20.307 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.util.reflection.ReflectionContextFactory)
2017-11-28 13:03:20.307 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.util.PatternMatcher)
2017-11-28 13:03:20.307 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (org.apache.struts2.util.ContentTypeMatcher)
2017-11-28 13:03:20.307 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (org.apache.struts2.dispatcher.StaticContentLoader)
2017-11-28 13:03:20.307 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.UnknownHandlerManager)
2017-11-28 13:03:20.307 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (org.apache.struts2.views.util.UrlHelper)
2017-11-28 13:03:20.308 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.util.TextParser)
2017-11-28 13:03:20.308 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (org.apache.struts2.dispatcher.DispatcherErrorHandler)
2017-11-28 13:03:20.308 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.security.ExcludedPatternsChecker)
2017-11-28 13:03:20.308 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.security.AcceptedPatternsChecker)
2017-11-28 13:03:20.310 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.DefaultBeanSelectionProvider : Loading global messages from [messageResources]
2017-11-28 13:03:20.699 INFO 7376 --- [nio-8080-exec-3] c.o.xwork2.spring.SpringObjectFactory : Setting autowire strategy to name
2017-11-28 13:03:21.764 ERROR 7376 --- [nio-8080-exec-3] c.o.x.interceptor.ParametersInterceptor : Developer Notification (set struts.devMode to false to disable this message):
Unexpected Exception caught setting 'cp' on 'class com.myapplication.account.actions.LoginNavigationAction: Error setting expression 'cp' with value ['false', ]
2017-11-28 13:03:21.769 ERROR 7376 --- [nio-8080-exec-3] c.o.x.interceptor.ParametersInterceptor : Developer Notification (set struts.devMode to false to disable this message):
Unexpected Exception caught setting 'forwardURL' on 'class com.myapplication.account.actions.LoginNavigationAction: Error setting expression 'forwardURL' with value ['/myapplication/html/login.html', ]
2017-11-28 13:03:21.844 INFO 7376 --- [nio-8080-exec-3] c.m.account.actions.LoginPageAction : ========================= Result from LoginPageAction: success
更新
当我尝试 java -jar myapplication.war 时,我可以访问我的静态页面,但我在访问 struts 页面时遇到另一个错误:
2017-11-29 08:55:41.536 WARN 7968 --- [nio-8080-exec-8] c.o.xwork2.util.fs.JarEntryRevision : Could not create JarEntryRevision for [jar:file:/C:/workspaces/workspace/dev/myapplication/target/myapplication-war-0.0.0.war]!
java.lang.NullPointerException: null
at com.opensymphony.xwork2.util.fs.JarEntryRevision.build(JarEntryRevision.java:52)
at com.opensymphony.xwork2.util.fs.DefaultFileManager.monitorFile(DefaultFileManager.java:97)
at com.opensymphony.xwork2.util.fs.DefaultFileManager.loadFile(DefaultFileManager.java:74)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadConfigurationFiles(XmlConfigurationProvider.java:1015)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadDocuments(XmlConfigurationProvider.java:167)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.init(XmlConfigurationProvider.java:134)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:239)
....
2017-11-29 08:55:41.636 WARN 7968 --- [nio-8080-exec-8] c.o.xwork2.util.fs.JarEntryRevision : Could not create JarEntryRevision for [jar:war:file:/C:/workspaces/workspace/dev/myapplication/target/myapplication-war-0.0.0.war*/WEB-INF/lib/struts2-core-2.3.34.jar]!
java.io.FileNotFoundException: war:file:\C:\workspaces\workspace\dev\myapplication\target\myapplication-war-0.0.0.war*\WEB-INF\lib\struts2-core-2.3.34.jar (The filename, directory name, or volume label syntax is incorrect)
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:219)
at java.util.zip.ZipFile.<init>(ZipFile.java:149)
at java.util.jar.JarFile.<init>(JarFile.java:166)
at java.util.jar.JarFile.<init>(JarFile.java:130)
at com.opensymphony.xwork2.util.fs.JarEntryRevision.build(JarEntryRevision.java:50)
...
2017-11-29 08:55:41.690 INFO 7968 --- [nio-8080-exec-8] c.o.x.c.p.XmlConfigurationProvider : Parsing configuration file [struts-default.xml]
2017-11-29 08:55:41.802 ERROR 7968 --- [nio-8080-exec-8] o.apache.struts2.dispatcher.Dispatcher : Dispatcher initialization failed
com.opensymphony.xwork2.config.ConfigurationException: Unable to load configuration.
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:70)
at org.apache.struts2.dispatcher.Dispatcher.getContainer(Dispatcher.java:978)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:446)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:490)
at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74)
...
Caused by: com.opensymphony.xwork2.config.ConfigurationException: Unable to load bean: type: class:com.opensymphony.xwork2.ObjectFactory
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:247)
at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:102)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:240)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67)
... 65 common frames omitted
Caused by: com.opensymphony.xwork2.config.ConfigurationException: Bean type class com.opensymphony.xwork2.ObjectFactory with the name struts has already been loaded by bean - jar:file:/C:/workspaces/workspace/dev/myapplication/target/myapplication-war-0.0.0.war!/WEB-INF/lib/struts2-core-2.3.34.jar!/struts-default.xml:65:72
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:231)
... 68 common frames omitted
拜托,有什么想法吗?
您是否尝试过将 jsp 文件从 src/main/webapp 文件夹简单地移动到 src/main/resources/META-INF/resources/WEB-INF? Servlet 3.0 规范允许在 src/main/resources/META-INF/resources/
中拥有动态页面
经过三天的研究,我可以修复它。
在开始迁移我的遗留应用程序之前,我创建了一些应用程序来测试 Spring Boot、Struts 2 和 Tomcat,它们都运行良好。问题是我的遗留系统有自己的父系统。我没有使用以下 spring 引导父项。
我不会用:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
</parent>
因此,根据 Spring 引导文档:
"Not everyone likes inheriting from the spring-boot-starter-parent POM. You may have your own corporate standard parent that you need to use or you may prefer to explicitly declare all your Maven configuration.
If you do not want to use the spring-boot-starter-parent, you can still keep the benefit of the dependency management (but not the plugin management) by using a scope=import dependency, as follows:"
<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
现在,应用程序能够显示每个 jsp/struts 页。
注意:我不需要放置任何特殊配置,如 ViewResolver 或我自己的 DispatcherServlet。根据@Sébastien PRAT 的建议,我刚刚添加了上述依赖项并将每个静态和 jsp 页面复制到“META-INF/resources”。其他文件夹选项是“resources/”、“static/”和“public/”。
更新
出现下面这个错误是因为嵌入式tomcat容器提供了两个不同的xworkapi相同文件路径(struts-default.xml),然后xworkapi 失败,因为尝试初始化同一个 bean 两次。因此,您应该将 struts 依赖范围从编译更改为提供。 Spring boot maven 插件将把你的 struts 依赖项复制到 web-inf/lib-provided 文件夹下。它可以作为可执行文件 war 正常工作,但如果您同时需要可执行文件和可部署文件,则应创建不同的配置文件以生成不同的文件。
com.opensymphony.xwork2.config.ConfigurationException: Unable to load configuration.
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:70)
at org.apache.struts2.dispatcher.Dispatcher.getContainer(Dispatcher.java:978)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:446)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:490)
at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74)
...
Caused by: com.opensymphony.xwork2.config.ConfigurationException: Unable to load bean: type: class:com.opensymphony.xwork2.ObjectFactory
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:247)
at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:102)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:240)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67)
... 65 common frames omitted
Caused by: com.opensymphony.xwork2.config.ConfigurationException: Bean type class com.opensymphony.xwork2.ObjectFactory with the name struts has already been loaded by bean - jar:file:/C:/workspaces/workspace/dev/myapplication/target/myapplication-war-0.0.0.war!/WEB-INF/lib/struts2-core-2.3.34.jar!/struts-default.xml:65:72
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:231)
... 68 common frames omitted
Struts 2 个范围:
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
<version>2.3.34</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.apache.struts</groupId>
<artifactId>struts-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.struts.xwork</groupId>
<artifactId>xwork-core</artifactId>
</exclusion>
</exclusions>
</dependency>
现在,我可以使用 java -jar myapplication.war.
生成可执行文件 war 和 运行
希望对您有所帮助。
我正在尝试将具有 spring 引导和 struts 2(struts.xml 文件)的 Web 应用程序从 Jboss 7.1.1 迁移到 tomcat 嵌入。
现在,我的配置是这样的:
Application.java
@SpringBootApplication()
@ServletComponentScan()
public class Application extends JbossDefaultPropertiesInitializer {
public static void main(String[] args) {
configureApplication(new SpringApplicationBuilder()).run(args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
setRegisterErrorPageFilter(false);
return configureApplication(builder);
}
private static SpringApplicationBuilder configureApplication(SpringApplicationBuilder builder) {
builder.initializers(new DefaultPropertiesInitializer());
return builder.sources(Application.class);
}
}
pom.xml
<resources>
<resource>
<directory>src/main/webapp</directory>
<targetPath>/static</targetPath>
<excludes>
<exclude>**/*.jsp</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/webapp</directory>
<targetPath>/WEB-INF/jsp</targetPath>
<includes>
<include>**/*.jsp</include>
</includes>
</resource>
</resources>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.6.RELEASE</version>
<configuration>
<mainClass>com.myapplication.Application</mainClass>
<executable>true</executable>
<layout>WAR</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
struts.devMode=true
每个过滤器、servlet 和侦听器都从 web.xml 迁移到@WebFilter、@WebListener 和@WebServlets。
当我开始 tomcat 时一切似乎都正常,我能够获得一些静态资源,如 html、css 和 js。
当我调用某些 struts 页面时,如 http://localhost:8080/myapplication/login.go,一切正常,过滤器和 servlet 被调用,我的操作被调用,但是当操作 returns "success" 调用“/myapplication/jsp/login.jsp”它不呈现。 jsp 文件未被调用或存在一些错误,我在控制台中什么也没有得到。
我的操作调用 jsp 页面之前的日志:
2017-11-28 13:03:19.881 INFO 7376 --- [nio-8080-exec-3] c.o.x.c.p.XmlConfigurationProvider : Parsing configuration file [struts-default.xml]
2017-11-28 13:03:19.933 WARN 7376 --- [nio-8080-exec-3] com.opensymphony.xwork2.util.DomHelper : Local DTD is missing for publicID: -//Apache Software Foundation//DTD Struts Configuration 2.5//EN - defined mappings: {-//Apache Struts//XWork 1.1.1//EN=xwork-1.1.1.dtd, -//Apache Software Foundation//DTD Struts Configuration 2.0//EN=struts-2.0.dtd, -//Apache Struts//XWork 1.0//EN=xwork-1.0.dtd, -//Apache Software Foundation//DTD Struts Configuration 2.1//EN=struts-2.1.dtd, -//Apache Struts//XWork 1.1//EN=xwork-1.1.dtd, -//Apache Struts//XWork 2.1.3//EN=xwork-2.1.3.dtd, -//Apache Software Foundation//DTD Struts Configuration 2.3//EN=struts-2.3.dtd, -//Apache Struts//XWork 2.0//EN=xwork-2.0.dtd, -//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN=struts-2.1.7.dtd, -//Apache Struts//XWork 2.1//EN=xwork-2.1.dtd, -//Apache Struts//XWork 2.3//EN=xwork-2.3.dtd}
2017-11-28 13:03:20.220 INFO 7376 --- [nio-8080-exec-3] c.o.x.c.p.XmlConfigurationProvider : Parsing configuration file [struts-plugin.xml]
2017-11-28 13:03:20.301 INFO 7376 --- [nio-8080-exec-3] c.o.x.c.p.XmlConfigurationProvider : Parsing configuration file [struts.xml]
2017-11-28 13:03:20.304 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (spring) for (com.opensymphony.xwork2.ObjectFactory)
2017-11-28 13:03:20.304 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.factory.ActionFactory)
2017-11-28 13:03:20.304 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.factory.ResultFactory)
2017-11-28 13:03:20.304 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.factory.ConverterFactory)
2017-11-28 13:03:20.304 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.factory.InterceptorFactory)
2017-11-28 13:03:20.304 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.factory.ValidatorFactory)
2017-11-28 13:03:20.304 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.factory.UnknownHandlerFactory)
2017-11-28 13:03:20.304 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.FileManagerFactory)
2017-11-28 13:03:20.305 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.XWorkConverter)
2017-11-28 13:03:20.305 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.CollectionConverter)
2017-11-28 13:03:20.305 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.ArrayConverter)
2017-11-28 13:03:20.305 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.DateConverter)
2017-11-28 13:03:20.305 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.NumberConverter)
2017-11-28 13:03:20.305 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.StringConverter)
2017-11-28 13:03:20.305 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.conversion.ConversionPropertiesProcessor)
2017-11-28 13:03:20.305 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.conversion.ConversionFileProcessor)
2017-11-28 13:03:20.305 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.conversion.ConversionAnnotationProcessor)
2017-11-28 13:03:20.305 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.conversion.TypeConverterCreator)
2017-11-28 13:03:20.306 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.conversion.TypeConverterHolder)
2017-11-28 13:03:20.306 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.TextProvider)
2017-11-28 13:03:20.306 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.LocaleProvider)
2017-11-28 13:03:20.306 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.ActionProxyFactory)
2017-11-28 13:03:20.306 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.conversion.ObjectTypeDeterminer)
2017-11-28 13:03:20.306 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (org.apache.struts2.dispatcher.mapper.ActionMapper)
2017-11-28 13:03:20.306 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (jakarta) for (org.apache.struts2.dispatcher.multipart.MultiPartRequest)
2017-11-28 13:03:20.306 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (org.apache.struts2.views.freemarker.FreemarkerManager)
2017-11-28 13:03:20.306 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (org.apache.struts2.views.velocity.VelocityManager)
2017-11-28 13:03:20.306 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (org.apache.struts2.components.UrlRenderer)
2017-11-28 13:03:20.306 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.validator.ActionValidatorManager)
2017-11-28 13:03:20.307 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.util.ValueStackFactory)
2017-11-28 13:03:20.307 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.util.reflection.ReflectionProvider)
2017-11-28 13:03:20.307 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.util.reflection.ReflectionContextFactory)
2017-11-28 13:03:20.307 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.util.PatternMatcher)
2017-11-28 13:03:20.307 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (org.apache.struts2.util.ContentTypeMatcher)
2017-11-28 13:03:20.307 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (org.apache.struts2.dispatcher.StaticContentLoader)
2017-11-28 13:03:20.307 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.UnknownHandlerManager)
2017-11-28 13:03:20.307 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (org.apache.struts2.views.util.UrlHelper)
2017-11-28 13:03:20.308 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.util.TextParser)
2017-11-28 13:03:20.308 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (org.apache.struts2.dispatcher.DispatcherErrorHandler)
2017-11-28 13:03:20.308 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.security.ExcludedPatternsChecker)
2017-11-28 13:03:20.308 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.AbstractBeanSelectionProvider : Choosing bean (struts) for (com.opensymphony.xwork2.security.AcceptedPatternsChecker)
2017-11-28 13:03:20.310 INFO 7376 --- [nio-8080-exec-3] o.a.s.c.DefaultBeanSelectionProvider : Loading global messages from [messageResources]
2017-11-28 13:03:20.699 INFO 7376 --- [nio-8080-exec-3] c.o.xwork2.spring.SpringObjectFactory : Setting autowire strategy to name
2017-11-28 13:03:21.764 ERROR 7376 --- [nio-8080-exec-3] c.o.x.interceptor.ParametersInterceptor : Developer Notification (set struts.devMode to false to disable this message):
Unexpected Exception caught setting 'cp' on 'class com.myapplication.account.actions.LoginNavigationAction: Error setting expression 'cp' with value ['false', ]
2017-11-28 13:03:21.769 ERROR 7376 --- [nio-8080-exec-3] c.o.x.interceptor.ParametersInterceptor : Developer Notification (set struts.devMode to false to disable this message):
Unexpected Exception caught setting 'forwardURL' on 'class com.myapplication.account.actions.LoginNavigationAction: Error setting expression 'forwardURL' with value ['/myapplication/html/login.html', ]
2017-11-28 13:03:21.844 INFO 7376 --- [nio-8080-exec-3] c.m.account.actions.LoginPageAction : ========================= Result from LoginPageAction: success
更新
当我尝试 java -jar myapplication.war 时,我可以访问我的静态页面,但我在访问 struts 页面时遇到另一个错误:
2017-11-29 08:55:41.536 WARN 7968 --- [nio-8080-exec-8] c.o.xwork2.util.fs.JarEntryRevision : Could not create JarEntryRevision for [jar:file:/C:/workspaces/workspace/dev/myapplication/target/myapplication-war-0.0.0.war]!
java.lang.NullPointerException: null
at com.opensymphony.xwork2.util.fs.JarEntryRevision.build(JarEntryRevision.java:52)
at com.opensymphony.xwork2.util.fs.DefaultFileManager.monitorFile(DefaultFileManager.java:97)
at com.opensymphony.xwork2.util.fs.DefaultFileManager.loadFile(DefaultFileManager.java:74)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadConfigurationFiles(XmlConfigurationProvider.java:1015)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadDocuments(XmlConfigurationProvider.java:167)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.init(XmlConfigurationProvider.java:134)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:239)
....
2017-11-29 08:55:41.636 WARN 7968 --- [nio-8080-exec-8] c.o.xwork2.util.fs.JarEntryRevision : Could not create JarEntryRevision for [jar:war:file:/C:/workspaces/workspace/dev/myapplication/target/myapplication-war-0.0.0.war*/WEB-INF/lib/struts2-core-2.3.34.jar]!
java.io.FileNotFoundException: war:file:\C:\workspaces\workspace\dev\myapplication\target\myapplication-war-0.0.0.war*\WEB-INF\lib\struts2-core-2.3.34.jar (The filename, directory name, or volume label syntax is incorrect)
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:219)
at java.util.zip.ZipFile.<init>(ZipFile.java:149)
at java.util.jar.JarFile.<init>(JarFile.java:166)
at java.util.jar.JarFile.<init>(JarFile.java:130)
at com.opensymphony.xwork2.util.fs.JarEntryRevision.build(JarEntryRevision.java:50)
...
2017-11-29 08:55:41.690 INFO 7968 --- [nio-8080-exec-8] c.o.x.c.p.XmlConfigurationProvider : Parsing configuration file [struts-default.xml]
2017-11-29 08:55:41.802 ERROR 7968 --- [nio-8080-exec-8] o.apache.struts2.dispatcher.Dispatcher : Dispatcher initialization failed
com.opensymphony.xwork2.config.ConfigurationException: Unable to load configuration.
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:70)
at org.apache.struts2.dispatcher.Dispatcher.getContainer(Dispatcher.java:978)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:446)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:490)
at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74)
...
Caused by: com.opensymphony.xwork2.config.ConfigurationException: Unable to load bean: type: class:com.opensymphony.xwork2.ObjectFactory
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:247)
at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:102)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:240)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67)
... 65 common frames omitted
Caused by: com.opensymphony.xwork2.config.ConfigurationException: Bean type class com.opensymphony.xwork2.ObjectFactory with the name struts has already been loaded by bean - jar:file:/C:/workspaces/workspace/dev/myapplication/target/myapplication-war-0.0.0.war!/WEB-INF/lib/struts2-core-2.3.34.jar!/struts-default.xml:65:72
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:231)
... 68 common frames omitted
拜托,有什么想法吗?
您是否尝试过将 jsp 文件从 src/main/webapp 文件夹简单地移动到 src/main/resources/META-INF/resources/WEB-INF? Servlet 3.0 规范允许在 src/main/resources/META-INF/resources/
中拥有动态页面经过三天的研究,我可以修复它。
在开始迁移我的遗留应用程序之前,我创建了一些应用程序来测试 Spring Boot、Struts 2 和 Tomcat,它们都运行良好。问题是我的遗留系统有自己的父系统。我没有使用以下 spring 引导父项。
我不会用:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
</parent>
因此,根据 Spring 引导文档:
"Not everyone likes inheriting from the spring-boot-starter-parent POM. You may have your own corporate standard parent that you need to use or you may prefer to explicitly declare all your Maven configuration.
If you do not want to use the spring-boot-starter-parent, you can still keep the benefit of the dependency management (but not the plugin management) by using a scope=import dependency, as follows:"
<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
现在,应用程序能够显示每个 jsp/struts 页。
注意:我不需要放置任何特殊配置,如 ViewResolver 或我自己的 DispatcherServlet。根据@Sébastien PRAT 的建议,我刚刚添加了上述依赖项并将每个静态和 jsp 页面复制到“META-INF/resources”。其他文件夹选项是“resources/”、“static/”和“public/”。
更新
出现下面这个错误是因为嵌入式tomcat容器提供了两个不同的xworkapi相同文件路径(struts-default.xml),然后xworkapi 失败,因为尝试初始化同一个 bean 两次。因此,您应该将 struts 依赖范围从编译更改为提供。 Spring boot maven 插件将把你的 struts 依赖项复制到 web-inf/lib-provided 文件夹下。它可以作为可执行文件 war 正常工作,但如果您同时需要可执行文件和可部署文件,则应创建不同的配置文件以生成不同的文件。
com.opensymphony.xwork2.config.ConfigurationException: Unable to load configuration.
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:70)
at org.apache.struts2.dispatcher.Dispatcher.getContainer(Dispatcher.java:978)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:446)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:490)
at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74)
...
Caused by: com.opensymphony.xwork2.config.ConfigurationException: Unable to load bean: type: class:com.opensymphony.xwork2.ObjectFactory
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:247)
at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:102)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:240)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67)
... 65 common frames omitted
Caused by: com.opensymphony.xwork2.config.ConfigurationException: Bean type class com.opensymphony.xwork2.ObjectFactory with the name struts has already been loaded by bean - jar:file:/C:/workspaces/workspace/dev/myapplication/target/myapplication-war-0.0.0.war!/WEB-INF/lib/struts2-core-2.3.34.jar!/struts-default.xml:65:72
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:231)
... 68 common frames omitted
Struts 2 个范围:
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
<version>2.3.34</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.apache.struts</groupId>
<artifactId>struts-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.struts.xwork</groupId>
<artifactId>xwork-core</artifactId>
</exclusion>
</exclusions>
</dependency>
现在,我可以使用 java -jar myapplication.war.
生成可执行文件 war 和 运行希望对您有所帮助。