Given a spring-boot application with jsp and layered jar, starting it according to blog post instructions produces FileNotFoundException from Tomcat's StandardJarScanner:

2020-08-30 15:07:26.578  WARN 16958 --- [           main] o.a.tomcat.util.scan.StandardJarScanner  :
Failed to scan [file:/path/to/spring-petclinic/target/bug-report/HikariCP-3.4.5.jar] from classloader hierarchy
java.io.FileNotFoundException: /path/to/spring-petclinic/target/bug-report/HikariCP-3.4.5.jar (No such file or directory)
        at java.util.zip.ZipFile.open(Native Method) ~[na:1.8.0_242]
        at java.util.zip.ZipFile.<init>(ZipFile.java:230) ~[na:1.8.0_242]
        at java.util.zip.ZipFile.<init>(ZipFile.java:160) ~[na:1.8.0_242]
        at java.util.jar.JarFile.<init>(JarFile.java:166) ~[na:1.8.0_242]
        at java.util.jar.JarFile.<init>(JarFile.java:130) ~[na:1.8.0_242]
        at org.apache.tomcat.util.compat.JreCompat.jarFileNewInstance(JreCompat.java:221) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
        at org.apache.tomcat.util.scan.JarFileUrlJar.<init>(JarFileUrlJar.java:65) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
        at org.apache.tomcat.util.scan.JarFactory.newInstance(JarFactory.java:49) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
        at org.apache.tomcat.util.scan.StandardJarScanner.process(StandardJarScanner.java:383) [tomcat-embed-core-9.0.37.jar:9.0.37]
        at org.apache.tomcat.util.scan.StandardJarScanner.processURLs(StandardJarScanner.java:318) [tomcat-embed-core-9.0.37.jar:9.0.37]
        at org.apache.tomcat.util.scan.StandardJarScanner.doScanClassPath(StandardJarScanner.java:270) [tomcat-embed-core-9.0.37.jar:9.0.37]

Tested under: spring-petclinic with spring-boot 2.3.3 release. You can find a reproducible example here. Run test.sh script

The problem appears to be that JarLauncher adds entries from classpath.idx:

file:/path/to/spring-petclinic/target/bug-report/BOOT-INF/classes/
file:/path/to/spring-petclinic/target/bug-report/BOOT-INF/lib/HdrHistogram-2.1.12.jar
file:/path/to/spring-petclinic/target/bug-report/BOOT-INF/lib/HikariCP-3.4.5.jar
[...]
file:/path/to/spring-petclinic/target/bug-report/HdrHistogram-2.1.12.jar
file:/path/to/spring-petclinic/target/bug-report/HikariCP-3.4.5.jar

Comment From: maxxedev

blog posts: https://spring.io/blog/2020/01/27/creating-docker-images-with-spring-boot-2-3-0-m1 https://spring.io/blog/2020/08/14/creating-efficient-docker-images-with-spring-boot-2-3

Comment From: philwebb

JSPs cannot be used with JAR files and unfortunately layered wars are not yet supported (issue #22195 is tracking that request).

The current error message isn't very helpful, so I'd like to dig into it a little more to see if we can't provide something better.

Comment From: aprantl

I am having this issue too since updating to 2.3.3. It actually does not only affect layered JARs. I get the same warning messages in the log once the (layered or non-layered) JAR is exploded and executed with java org.springframework.boot.loader.JarLauncher --cp my-application-root. According to the message BOOT-INF\lib is missing in the URL path lookup. The warn If I execute the JAR directly, there are no warnings.

JSPs weren't support by default - agreed. But there have been rather easy workarounds as described here. It would be unfortunate if the new LaunchedURLClassLoader, the handling of the classpath in org.springframework.boot.loader.Launcher, or something else now breaks with this workaround.

Comment From: scottfrederick

The root cause of this issue was identified by @wilkinsona in a separate issue. The output from the provided sample app shows the same duplicate entries for each jar in the classloader, with a valid jar entry in BOOT-INF/lib/ and an invalid entry pointing to the local file system.

Comment From: scottfrederick

Closing this as a duplicate of #24192 since the other issue identifies the root cause.