question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Resources in Spring Boot artifacts return the wrong URL

See original GitHub issue

Hi 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:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
michael-simonscommented, Mar 23, 2021

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.

0reactions
lukehutchcommented, Mar 23, 2021

Awesome, thanks for reporting back!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring Boot 1.4 : class path resource [] cannot be resolved to ...
This happens in spring boot version 1.4 when you have spring data JPA jars on your dependency and you have no classes in...
Read more >
Bad URL or missing artifact for Spring Boot CLI 1.3.3? #72
This is because repo.spring.io is currently screwed up. Give it some time and it'll start working again.
Read more >
6. Resources - Spring
Some of the most important methods from the Resource interface are: getInputStream() : locates and opens the resource, returning an InputStream for reading...
Read more >
Spring Boot, Maven and Eclipse Errors and TroubleShooting ...
We do not want you to get stuck because of a simple error. This 50 page troubleshooting guide and faq is our way...
Read more >
How to Avoid the Java FileNotFoundException When Loading ...
Get started with Spring 5 and Spring Boot 2, through the Learn ... Let's see how Java allows us to access resource files...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found