Nayan S
Nayan S

Reputation: 33

Spring Boot Executable jar structure

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

Upvotes: 2

Views: 6934

Answers (2)

Riddhi Gohil
Riddhi Gohil

Reputation: 1818

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

Upvotes: 2

Andy Wilkinson
Andy Wilkinson

Reputation: 116111

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.

Upvotes: 11

Related Questions