[英]Spring Boot JSF packaging as a JAR
我正在尝试用jsf和gradle创建一个spring boot应用程序。
到目前为止,在开发过程中一切都很好。 当我想运行我的应用程序时,我只输入了gradle bootRun,应用程序启动了,我可以在“localhost”下访问它。
现在我处于某个时间点,我想部署应用程序,因此我运行命令'gradle clean distTar',它创建要部署的tar文件。
运行生成的脚本并通过浏览器访问我的应用程序后,我只得到一条带有消息的404。
index.xhtml Not Found in ExternalContext as a Resource
同样在jar文件中,没有包含任何html文件。 我用命令将它们包含在jar中
from ("${projectDir}/src/main/webapp/"){
into('resources')
}
请参阅https://spring.io/blog/2013/12/19/serving-static-web-content-with-spring-boot,这些文件应该是可访问的。 但仍然没有改变。
有没有其他人有线索? 我究竟做错了什么?
BR
我一直在努力解决这个问题,最终设法提出了一个有效的解决方案。
如: https://stackoverflow.com/a/9473487/4250114如果您使用Servlet3.x(您可能使用的是SpringBoot)。
对我来说,maven中的结构看起来像下面的工作:
src |-main | ... |-resources |-META-INF |-faces-config.xml |-resources |-test.xhtml
所以在jar中它应该是:
|-META-INF |-faces-config.xml |-resources |-test.xhtml
按照给定的结构创建胖罐:
Demo
└── src
| ├── main
| │ ├── java
| │ │ └── org
| │ │ └── demo
| │ │ └── App.java
| │ └── resources
| | |
| │ └── application.properties
| | |
| | └── META-INF
| | | └── resources
| | | └── jsp
| | └── static
| | └── css
| | └── js
| |
| └── test
| └── java
| └── org
| └── demo
| └── App.java
├──── pom.xml
基于来自https://github.com/spring-projects/spring-boot/issues/8299的信息以及基于SpringBoot + Jetty的输出
2018-01-15 15:57:03 [main] INFO o.j.jetty.JsfJettyServerCustomizer - Setting Jetty classLoader to META-INF/resources directory
我在Gradle文件中使用了这个:
jar {
baseName = 'csm'
version = "0.0.1-SNAPSHOT"
from("build/docs/"){
into("generated/docs/")
}
from("src/main/resources/"){
include("**")
}
// JSF and SpringBoot and Jetty require all webapp files to be in a very particular location.
// See: https://github.com/spring-projects/spring-boot/issues/8299
from ("${projectDir}/src/main/webapp/"){
into('META-INF/resources')
}
}
/BOOT-INF
/META-INF/
/resources/
/WEB-INF/
web.xml
index.jsf
blah.xhtml
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.