Spring Boot是否可以使用JAR包装来提供JSP? [英] Is it possible with Spring Boot to serve up JSPs with a JAR packaging?
问题描述
I'm familiar with the Spring Boot JSP sample application
但是,该示例使用了WAR
包装.可以用<packaging>JAR</packaging>
做同样的事情吗?
However that example uses the WAR
packaging. Is it possible to do the same with <packaging>JAR</packaging>
?
我的目标是将JSP
放在src/main/resources/jsp
下,以简化我的应用程序的结构.
My goal is to put JSP
s under src/main/resources/jsp
to simplify the structure of my app.
推荐答案
正如@Andy Wilkinson所说,与JSP相关的局限性.请将您的应用程序打包为war
并以jar
执行.在春季现场有记录.
As @Andy Wilkinson said, there are limitations related to JSP. Please package your application as war
and execute as jar
. This is documented at spring site.
对于Tomcat,如果使用war打包,它应该可以工作,即可执行的war将可以工作(...). 由于Tomcat中采用了硬编码的文件模式,因此可执行jar无法正常工作.
- 27.3.5 JSP限制
- jsp示例
- 27.3.5 JSP limitations
- jsp sample
不建议使用的旧答案
是的,这可以通过Spring Boot来实现.
Yes, this is possible with Spring Boot.
看这个例子: https://github.com/mariuszs/spring-boot-web-jsp-example .
For doing this use spring-boot-maven-plugin or gradle equivalent.
使用此插件jar可以执行,并且可以提供JSP文件.
With this plugin jar is executable and can serve JSP files.
$ mvn package
$ java -jar target/mymodule-0.0.1-SNAPSHOT.jar
或者只是
$ mvn spring-boot:run
这篇关于Spring Boot是否可以使用JAR包装来提供JSP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!