Why does ContextClassLoader return an exclamation mark path?

I am trying to open a file in a bank in WEB-INF / lib using

Thread.currentThread().getContextClassLoader(); URL url=classLoader.getResource(myconfig); 

In the debugger, I see:

 jar:file:/C:/apache-tomcat/webapps/mywebapp/WEB-INF/lib/myjarresource.jar! /conf/configuration.xml 

Why is there a β€œ!” In the file path? I think for this reason the application cannot open this file. How to get the right way? Thanks.

+4
source share
2 answers

This means that everything that comes after ! located inside the jar file.

In the case of myjarresource.jar!/conf/configuration.xml open myjarresource.jar with a compression utility such as 7-zip and you will see that it contains conf/configuration.xml .

+4
source

The JarURLConnection javadoc describes the syntax of the JAR URL:

JAR URL Syntax: jar:! / {Entry}

So '!' indicates that you are 'enter' the java archive.

Edit: I believe that you cannot do File file=new File(url.toURI()) because of a ":" that appears twice in the generated URI and does not meet the URI specifications (chapters 2.2 and 3), so this is rejected in the ctor file.

+3
source

Source: https://habr.com/ru/post/1399347/


All Articles