Reputation: 24248
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.
Upvotes: 15
Views: 10971
Reputation: 4572
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.
Upvotes: 7
Reputation: 62593
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
.
Upvotes: 10