【发布时间】:2012-03-01 07:09:39
【问题描述】:
以下代码在 Tomcat 中运行良好,但在 WebSphere 6.1 中调用 getResource(...) 返回 null。我试过同时使用 Thread.currentThread().getClassLoader() 和 MyClass.class.getClassLoader() - 两者都返回 null。
URL url = null;
ClassLoader cl = MyClass.class.getClassLoader();
LOG.info("Using class's classloader.");
url = cl.getResource("resources/AConfigFile.xml");
if(url == null) {
throw new RuntimeException("The ClassLoader returned null for the URL of the " +
"the XML Document. This is definitely not right.");
}
...我也试过这个,没有运气...
URL url = null;
url = MyClass.class.getResource("resources/AConfigFile.xml");
if(url == null) {
throw new RuntimeException("The ClassLoader returned null for the URL of the " +
"the XML Document. This is definitely not right.");
}
这是怎么回事?如何正确获取类路径上资源的 URL?
【问题讨论】:
标签: java websphere classpath classloader