Resources in Spring Boot artifacts return the wrong URL
See original GitHub issueHi Luke.
This is basically the sequel to #435. A user has brought to my attention that the release 4.8.91 (see https://github.com/classgraph/classgraph/releases/tag/classgraph-4.8.91) returns invalid class path element URIs for packaged resources in this https://github.com/michael-simons/neo4j-migrations/issues/179 ticket.
Find a reproducer attached. NOTE: The thing must be packaged with mvn clean package
and executed with java -jar target/classgraph_resources_issue-0.0.1-SNAPSHOT.jar
, running from the IDE is not enough. Commands are shown below so that you don’t have to change anything in the pom to switch versions:
Reproducer: classgraph_resources_issue.zip
The core issue is demonstrated between here:
try (ScanResult scanResult = new ClassGraph()
.whitelistPaths("foo").scan()) {
List<Resource> resources = scanResult.getResourcesWithExtension("cypher")
.stream()
.collect(Collectors.toList());
resources.forEach(System.err::println);
if (resources.size() > 1) {
throw new RuntimeException(":(");
}
System.err.println("Reading via Resource#open");
try (InputStream in = resources.get(0).open()) {
System.err.println(readInputStream(in));
} catch (IOException e) {
e.printStackTrace();
}
System.err.println("Reading via Resource#getURL().openStream()");
System.err.println("URL is " + resources.get(0).getURL());
try (InputStream in = resources.get(0).getURL().openStream()) {
System.err.println(readInputStream(in));
} catch (IOException e) {
e.printStackTrace();
}
}
Classgraph 4.8.90
Run with
mvn clean package -Dclassgraph.version=4.8.90 && java -jar target/classgraph_resources_issue-0.0.1-SNAPSHOT.jar
Expected output
jar:file:/Users/msimons/Downloads/cg/classgraph_resources_issue/target/classgraph_resources_issue-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes/foo/a.cypher
Reading via Resource#open
asd
Reading via Resource#getURL().openStream()
URL is jar:file:/Users/msimons/Downloads/cg/classgraph_resources_issue/target/classgraph_resources_issue-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes/foo/a.cypher
asd
Classgraph 4.8.102
Run with
mvn clean package -Dclassgraph.version=4.8.102 && java -jar target/classgraph_resources_issue-0.0.1-SNAPSHOT.jar
Resolving fails (notice the double BOOT-INF
). I expect that getURL
returns something that is immediate usable, too.
jar:file:/Users/msimons/Downloads/cg/classgraph_resources_issue/target/classgraph_resources_issue-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/BOOT-INF/classes/foo/a.cypher
Reading via Resource#open
asd
Reading via Resource#getURL().openStream()
URL is jar:file:/Users/msimons/Downloads/cg/classgraph_resources_issue/target/classgraph_resources_issue-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/BOOT-INF/classes/foo/a.cypher
java.io.FileNotFoundException: JAR entry BOOT-INF/classes/foo/a.cypher not found in /Users/msimons/Downloads/cg/classgraph_resources_issue/target/classgraph_resources_issue-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
Thank you very much for the quick fix. Works for
neo4j-migrations
and after battling failsafe and Spring Boot’s fat jar for a while, I have a working integration test, too.Awesome, thanks for reporting back!