ClasspathFileSource does not work with spring boot fat jar
See original GitHub issueThe case is that I need to fire up spring boot app with some external mocks using wiremock (duh). The ClasspathFileSource
finds the path in the jar but it fails to load the stub mappings.
return FluentIterable.from(toIterable(zipFile.entries())).filter(new Predicate<ZipEntry>() {
public boolean apply(ZipEntry jarEntry) {
return !jarEntry.isDirectory() && jarEntry.getName().startsWith(path);
}
}).transform(new Function<ZipEntry, TextFile>() {
public TextFile apply(ZipEntry jarEntry) {
return new TextFile(getUriFor(jarEntry));
}
}).toList();
I suspect that this line: return !jarEntry.isDirectory() && jarEntry.getName().startsWith(path);
is problematic since spring boot fat JAR entries do not start with the $path they do start with BOOT-INF/classes/$path/....
- so in this case ClasspathFileSource
returns empty list.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:10
Top Results From Across the Web
ClasspathFileSource does not work with spring boot fat jar #725
The ClasspathFileSource finds the path in the jar but it fails to load the stub mappings. return FluentIterable.from(toIterable(zipFile.entries() ...
Read more >Reading file inside Spring boot fat jar - Stack Overflow
I have a file I put in the resource file, let's call it path and I was not able to read it. @madoke...
Read more >The Executable Jar Format - Spring
Spring Boot takes a different approach and lets you actually nest jars directly. 1.1. The Executable Jar File Structure. Spring Boot Loader-compatible jar...
Read more >Running a Spring Boot App with Maven vs an Executable Jar
In this tutorial, we'll explore the differences between starting a Spring Boot web application via the mvn spring-boot:run command and ...
Read more >Fat jar unable to find classpath file inside /resources package
I created a fat jar using Spring boot. ... be resolved to absolute file path because it does not reside in the file...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
We have a similar issue wherein our wiremock mappings are packaged in a nested jar (under WEB-INF/lib) in the Spring Boot war. The following is how we solved it
I had a similar problem because my resource files were located within a nested jar within the Spring Boot 2 UberJar.
I wrote a simple
FileSource
implementation, which uses Spring to load the resources, which works perfectly, because Spring nows how to load resources from within nested jars:Just use this
FileSource
when configuring WireMock and you are good to go: