2

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).

Nayan S
  • 33
  • 2
  • 8

2 Answers2

11

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.

Andy Wilkinson
  • 108,729
  • 24
  • 257
  • 242
  • 1
    As usual, I thought I'll learn new tool skipping reference guide. And again, I was reminded thats anti-pattern. Makes sense that jar packaging will ignore webapp. – Nayan S Oct 29 '14 at 20:21
  • In this case my fat jar contains, META-INF/resources/index.jsp. My application.properties has , spring.mvc.view.prefix = /resources/ - Is this correct? – prostý člověk May 26 '19 at 15:00
  • @ThangavelLoganathan It sounds like you're trying to use JSPs in an executable jar. This is not supported. We generally recommend against the use of JSPs. If you really want or need to use them, then you must use war packaging. – Andy Wilkinson May 27 '19 at 07:40
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
Riddhi Gohil
  • 1,758
  • 17
  • 17