Icarus3
Icarus3

Reputation: 2350

How to get InputStream from class which is in nested jar?

I am working with Spring boot jar and I have got nested jars in my structure. I am trying to read the raw bytes from the class file. I would like to get InputStream from following URL

"jar:file:/D:/work/dev/target/first.jar!/BOOT-INF/lib/second.jar!/a/b/c/Data.class"

I have tried

InputStream i = new URL( str ).openStream();

But this does not work ( FileNotFoundException ). I do not want to use spring-boot's API. Since that URL looks pretty standard I am hoping that there should be a way to achieve this.

Upvotes: 0

Views: 620

Answers (1)

Tarlog
Tarlog

Reputation: 10154

Is "second.jar" in the classpath?

If yes, use the Classloader.getResourceAsStream()

For example:

Thread.currentThread().getContextClassLoader().getResourceAsStream("a/b/c/Data.class")

Upvotes: 1

Related Questions