Spring Boot Executable jar structure

╄→尐↘猪︶ㄣ 提交于 2019-12-01 07:52:38

问题


I'm trying to run Spring Boot sample application. And I added couple of images in "images" folder under webapp folder (same level as WEB-INF).

I created executable jar, and these images are displayed correctly on web pages.

But, I'm scratching my head where is this images folder in executable jar? Are these images in one of the lib jar?

Thanks in advance.

UPDATE: After trying same jar on another machine the question changes altogather. Now, I can confirm that the images are not part of executable "fat" jar, as those images are not coming up on webpages. Going further, none of the files under "webapp" is packaged in jar. I have put spring-boot-maven-plugin plugin in pom and using "mvn package" to create the jar. In my src project, webapp is under src/main (same level as java and resource).


回答1:


This is covered in the documentation about static resources:

Do not use the src/main/webapp folder if your application will be packaged as a jar. Although this folder is a common standard, it will only work with war packaging and it will be silently ignored by most build tools if you generate a jar.

You should place your static resources in src/main/resources instead.




回答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


来源:https://stackoverflow.com/questions/26517324/spring-boot-executable-jar-structure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!