调试getResource * [英] Debugging getResource*

查看:106
本文介绍了调试getResource *的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何调试 getResource - 失败的方法,返回null?

How do you debug getResource-style methods that are failing, returning null?

我确定它正在查找的文件是存在的,但它返回NULL。我怎么知道它试图找出任何不匹配的东西?

I am sure the file it's looking for is there, but it's returning NULL. How do I know what it is looking for to try to spot any mismatch?

推荐答案

因为 getResource( )搜索类路径(正如其他人提到的那样),在问题 getResource()调用之前转储正在搜索的实际类路径可能会有所帮助:

Since getResource() searches the classpath (as others have mentioned), it might be helpful to dump the actual classpath being searched before your problemsome getResource() call:

log.debug("classpath is: " + System.getProperty("java.class.path"));

//the line that is returning null
... = Thread.currentThread().getContextClassLoader().getResource("foobar");

可能发生的事情是你认为在类路径上的文件/目录实际上不是(也许一路上某处设置了无效路径。)

What is probably happening is that the files/directories you think are on the classpath are actually not (perhaps an invalid path is being set somewhere along the way).

这篇关于调试getResource *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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