String path = ConnPool.class.getPackage().getName().replaceAll("//.", "/")+"/Config.xml";
URL url = null;
try {
if (Thread.currentThread().getContextClassLoader() != null) {
url = Thread.currentThread().getContextClassLoader().getResource(path);
}
if (url == null) {
url = ConnPool2.class.getClassLoader().getResource(path);
}
if(url ==null) {
url = ConnPool2.class.getClassLoader().getResource("/"+path);
}
if(url != null) {
JAXPConfigurator.configure(url.getFile(), false);
}
else{
String strURL = ConnPool2.class.getProtectionDomain().getCodeSource().getLocation().getPath();
strURL += ConnPool.class.getPackage().getName().replaceAll("//.", "/")+"/Config.xml";
JAXPConfigurator.configure(strURL, false);
}
} catch (Exception e) {
try {
InputStream in = ConnPool.class.getResourceAsStream(path);
BufferedReader reader= new BufferedReader(new InputStreamReader(in));
} catch (Exception ex) {
InputStream in = ConnPool.class.getResourceAsStream("/"+path);
BufferedReader reader= new BufferedReader(new InputStreamReader(in));
}
}
try {
Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
从Jar包获取资源的方法
最新推荐文章于 2024-06-02 17:15:32 发布