检查包是否存在 [英] checking whether a package is existent or not
本文介绍了检查包是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在我的java安装中检查javax.servlet。*之类的包是否存在?
How can i check whether a package like javax.servlet.* exists or not in my installation of java?
推荐答案
Java只能告诉你它是否可以加载一个类。它无法告诉你是否存在包,因为没有加载包,只有类。
Java can only tell you if it can load a class. It can't tell you if a package exists or not because packages aren't loaded, only classes.
唯一的方法是尝试从中加载一个类包。例如,对于javax.servlet。*你可以这样做:
The only way would be by trying to load a class from that package. e.g., For javax.servlet.* you could do:
try {
Class.forName("javax.servlet.Filter");
return true;
} catch(Exception e) {
return false;
}
这篇关于检查包是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文