Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
828 views
in Technique[技术] by (71.8m points)

maven - Is it possible with Spring Boot to serve up JSPs with a stand alone JAR packaging

I try to build Spring Boot with JSP to jar packaging. I build project and it works fine when I run it with this commands

$ mvn package

$ java -jar target/mymodule-0.0.1-SNAPSHOT.jar

but when I go to target directory ($cd target) and try

$java -jar mymodule-0.0.1-SNAPSHOT.jar

the application runs fine but when I open browser and try to open the page I get error "There was an unexpected error (type=Not Found, status=404). /WEB-INF/jsp/index.jsp"

I found this question, but when I try it I met the same problem Is it possible with Spring Boot to serve up JSPs with a JAR packaging

My questions is Why it works when I try

$ java -jar target/mymodule-0.0.1-SNAPSHOT.jar

and doesn't work when I try

$cd target

$java -jar mymodule-0.0.1-SNAPSHOT.jar

How can I solve it?

EDIT

There is not WEB-INF directory into jar or target directory and when I put it there it doesn't help

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you are using embedded Tomcat, Spring Boot doesn't support using JSPs in an executable jar:

With Tomcat it should work if you use war packaging, i.e. an executable war will work, and will also be deployable to a standard container (not limited to, but including Tomcat). An executable jar will not work because of a hard coded file pattern in Tomcat.

It works when you try java -jar target/mymodule-0.0.1-SNAPSHOT.jar because the JSPs are available on the filesystem from src/main/webapp which Spring Boot configures as a document root for convenience during development. When you move into the target directory, the src/main/webapp folder is no longer available so the JSPs stop working.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...