Skip to content

Classpath resources not found using layer-tools #42591

@ferblaca

Description

@ferblaca

Context

We are migrating our applications to using layer-tools but we are finding different behaviors in how applications search for classpath resources through the use of the PathMatchingResourcePatternResolver class.

It seems that the main problem is when using as location pattern an expression starting with wildcards, for example: classpath*:/**/*.avsc.

We have created a simple application that reproduces the case we are discussing.

Steps to reproduce

  1. Download application:
git clone https://github.com/ferblaca/DemoPathMatchingResourcePatternResolverApplication.git
  1. Compile:
cd DemoPathMatchingResourcePatternResolverApplication
mvn clean install
  1. Extract the FATJAR with layer-tools and start the application:
cd boot/target
java -Djarmode=tools -jar boot-0.0.1-SNAPSHOT.jar  extract --layers --destination extracted
cd extracted/application
mkdir lib
cp ../*/lib/*.jar lib/.
java -jar boot-0.0.1-SNAPSHOT.jar

Expected outcome

Using as AntPattern path classpath*:/**/*.avsc the application finds all the .avsc files that are in the classpath inside the jar resources of the artifact module:

+++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++ Resource: URL [jar:file:/home/fbc/workspaces/ferblaca/demoPathMatchingResolver/demoPathMatchingResourcePatternResolver/boot/target/extracted.fer/application/lib/artifact-0.0.1-SNAPSHOT.jar!/demo/statics/avro/file.avsc]
++++++++++ Resource: URL [jar:file:/home/fbc/workspaces/ferblaca/demoPathMatchingResolver/demoPathMatchingResourcePatternResolver/boot/target/extracted.fer/application/lib/artifact-0.0.1-SNAPSHOT.jar!/demo/statics/avro/file3.avsc]
++++++++++ Resource: URL [jar:file:/home/fbc/workspaces/ferblaca/demoPathMatchingResolver/demoPathMatchingResourcePatternResolver/boot/target/extracted.fer/application/lib/artifact-0.0.1-SNAPSHOT.jar!/demo/statics/avro/file2.avsc]
+++++++++++++++++++++++++++++++++++++++++++++++++

Observed outcome

The application running in layer-tools mode does NOT find the .avsc resources:

+++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++ NO RESOURCES FOUND!!!
++++++++++++++++++++++++++++++++++++++++++++++++

Details of tests performed

Application Type AntPattern Path Result
FATJAR classpath*:/**/*.avsc 🆗
LAYER-TOOLS classpath*:/**/*.avsc
LAYER-TOOLS classpath*:/demo/**/*.avsc 🆗

Versions

Spring-Boot version 3.3.4

Metadata

Metadata

Assignees

Labels

for: external-projectFor an external project and not something we can fix

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions