spring-projects / spring-boot

Spring Boot
https://spring.io/projects/spring-boot
Apache License 2.0
74.96k stars 40.65k forks source link

org.springframework.boot.loader.jar.JarURLConnection doesnot work under some condition #20227

Closed islandoo closed 4 years ago

islandoo commented 4 years ago

The springboot support url format like this

jar:file:/xxx/xxx-jar!/yyy-jar!/zzz.xml

But in my application, my url format is like this:

jar:file:/xxx/xxx-jar!/www-jar!/yyy-jar!/zzz.xml

There is one more jar in it, but JarURLConnection cannot support this scenario,I hope you can improve it, the only thing we should do is just one line of code below.

org.springframework.boot.loader.jar.JarURLConnection line 273

The code is

      JarEntry jarEntry = jarFile.getJarEntry(entryName.toCharSequence());

this should be changed to

      JarEntry jarEntry = connectionJarFile.getJarEntry(entryName.toCharSequence());

I had tried, it worked very well.I even think it is a bug.

Thanks!

wilkinsona commented 4 years ago

@islandoo Thank you for the report and analysis of the problem. Before we can consider making a change, we will need to understand exactly what’s happening. To help is to do that, please provide a small sample that reproduces the problem you have described.

islandoo commented 4 years ago

My application is a little complicated and irrelevant to this issue.My requirement is just that Url url = new URL("jar:file:/xxx/xxx.jar!/www.jar!/yyy.jar!/zzz.xml"); url.openConnection().toInputStream()

xxx.jar and www.jar are all the fatjars following the springboot standard,yyy.jar is a normal jar. xxx.jar is my application fatjar, depending on www.jar,my framework code will resolve www.jar. But the code above does not work!

Let's look up the org.springframework.boot.loader.jar.JarURLConnection line 273(version 2.2.4.RELEASE) JarEntry jarEntry = jarFile.getJarEntry(entryName.toCharSequence()); I think there must be something wrong. The Variable 'jarFile' should be replaced by 'connectionJarFile', If I do it, the code worked well.

As there are TWO ‘!/’ at most in the URL in springboot framework, the code is OK.But I hope the scenario with more '!/' should be considered seriously.

Thanks!

wilkinsona commented 4 years ago

I disagree that your application is irrelevant to this issue. Seeing your application, or some equivalent code that reproduces the problem, would have allowed us to be certain that we understand the problem you're seeing.

From the information that you have provided, it sounds like you are trying to nest one fat jar within another. This isn't supported at the moment and we do not have any plans to support it in the future. Adding support would introduce too much complexity for insufficient benefit. Unfortunately, there is quite a bit more to it than just dealing with multiple !/ entries in the URL.

I would recommend that you revisit the packaging of your application so that only the outer-most jar is a fat jar and all the jars nested within it are standard jar files.

Thank you anyway for the suggestion. If I have misunderstood what you are trying to do, please provide a small sample (it need not be your actual application) that reproduces the problem and we can take another look.

islandoo commented 4 years ago

Yeah.You had understood me totally.It is not easy to describe the issue through comments. It is just fine that springboot would not support the scenario.No problem! Thanks for your reply.And so quick.^_^

What confuse me most is the code below JarURLConnection line 271(version 2.2.4.RELEASE) while ((separator = spec.indexOf(SEPARATOR, index)) > 0) { if there is only TWO '!/' in URL, the code does not repeat twice, in my opinion.The 'while' could be replaced by 'if'. As I saw the 'while' here, so I thought springboot had the plan to support it! Misunderstanding

Thanks again!