Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...