[英]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.