Spring Boot 是否可以提供带有 JAR 包装的 JSP? [英] Is it possible with Spring Boot to serve up JSPs with a JAR packaging?

查看:24
本文介绍了Spring Boot 是否可以提供带有 JAR 包装的 JSP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我熟悉 Spring Boot JSP 示例应用程序

I'm familiar with the Spring Boot JSP sample application

然而,该示例使用 WAR 包装.是否可以对 JAR 做同样的事情?

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 JSPs under src/main/resources/jsp to simplify the structure of my app.

推荐答案

正如@Andy Wilkinson 所说,JSP 存在一些限制.请将您的应用程序打包为 war 并作为 jar 执行.这在 spring 站点上有记录.

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 将无法运行.

With Tomcat it should work if you use war packaging, i.e. an executable war will work (...). An executable jar will not work because of a hard coded file pattern in Tomcat.

  • 27.3.5 JSP限制
  • jsp 示例
  • 已弃用的旧答案

    是的,这可以通过 Spring Boot 实现.

    Yes, this is possible with Spring Boot.

    看看这个例子:https://github.com/mariuszs/spring-boot-web-jsp-example.

    为此使用 spring-boot-maven-plugin 或 gradle 等价物.

    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.war 
    

    (注意上面命令中工件的扩展名.war)或者只是

    (Note the extension of the artifact in the above command .war) or just

    $ mvn spring-boot:run
    

    这篇关于Spring Boot 是否可以提供带有 JAR 包装的 JSP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆