为什么ContextClassLoader返回带有感叹号字符的路径? [英] Why ContextClassLoader returns path with exclamation character?

查看:256
本文介绍了为什么ContextClassLoader返回带有感叹号字符的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在WEB-INF / lib中用jar打开文件

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.

推荐答案

这意味着之后的任何内容! 里面 JAR文件。

It means whatever comes after the ! is inside the JAR file.

如果是 myjarresource.jar!/conf/configuration.xml ,使用压缩实用程序(如7-zip)打开 myjarresource.jar ,您将看到它包含 conf / configuration。 xml

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.

这篇关于为什么ContextClassLoader返回带有感叹号字符的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆