I try to open file in jar in WEB-INF/lib with
Thread.currentThread().getContextClassLoader();
URL url=classLoader.getResource(myconfig);
In debugger I can see:
jar:file:/C:/apache-tomcat/webapps/mywebapp/WEB-INF/lib/myjarresource.jar!
/conf/configuration.xml
Why in file path is "!" ? I think for this reason application cannot open this file. How to receive correct path? Thanks.
It means whatever comes after the !
is inside the JAR file.
In case of myjarresource.jar!/conf/configuration.xml
, open up myjarresource.jar
using a compression utility such as 7-zip and you will see that it contains conf/configuration.xml
.
In the JarURLConnection javadoc , the syntax of a JAR URL is described:
The syntax of a JAR URL is: jar:!/{entry}
So '!' indicates that you 'enter' the java archive.
Edit:
I believe that you cannot do File file=new File(url.toURI())
because of the ":" which appears twice in the generated URI and is not compliant with the URI specifications(chapter 2.2 and 3) therefore this is rejected in the File ctor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With