问题
I am trying to create a spring boot app with jsf and gradle.
So far, during development everything was fine. When I wanted to run my App I just typed gradle bootRun, the app started and I was able to access it under 'localhost'.
Now I am at a point of time, where I want to deploy the app, therefore I run the command 'gradle clean distTar' which creates the tar file to deploy.
After running the generated script and accessing my app via Browser I just get an 404 with the message.
index.xhtml Not Found in ExternalContext as a Resource
Also in the jar file, there aren't any html files included. I included them in the jar with the command
from ("${projectDir}/src/main/webapp/"){
into('resources')
}
Referring to https://spring.io/blog/2013/12/19/serving-static-web-content-with-spring-boot this files should be accessible. But still nothing changed.
Does anyone else have a clue? What am I doing wrong?
BR
回答1:
I've been also struggling with this thing and finally managed to come up with a working solution.
As stated in: https://stackoverflow.com/a/9473487/4250114 if you use Servlet3.x (and you probably are with SpringBoot).
For me structure in maven looks like below worked:
src |-main | ... |-resources |-META-INF |-faces-config.xml |-resources |-test.xhtml
So in jar it should be:
|-META-INF |-faces-config.xml |-resources |-test.xhtml
回答2:
Follow the given structure to create fat jar :
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
回答3:
Based on information from https://github.com/spring-projects/spring-boot/issues/8299 and also based on the output from SpringBoot+Jetty
2018-01-15 15:57:03 [main] INFO o.j.jetty.JsfJettyServerCustomizer - Setting Jetty classLoader to META-INF/resources directory
I used this in my Gradle file:
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
来源:https://stackoverflow.com/questions/29461109/spring-boot-jsf-packaging-as-a-jar