Java:运行时检查类是否存在 [英] Java: Checking while run time if class exists

查看:228
本文介绍了Java:运行时检查类是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一种依赖于第三方库的软件。由于许可协议,该库不能与软件一起发货,用户必须在启动程序时已经在本地使用库。

I am working on a software which depends on an 3rd party library. Due to license agreements this library cannot be shipped along with the software and the user has to have the library already locally when starting the program.

有没有办法检查这个特定的库存在于类路径中,可以加载?如果不是,我想提供一个对话框,允许用户指向该位置,并将该位置动态添加到类路径。

Is there any way to check if this particular library exist in the class path and can be loaded? If not I would like to offer a dialog to allow the user pointing to the location and add this location to the class path dynamically.

感谢您的帮助!

推荐答案

尝试这样:

try {
    Class<?> clazz = Class.forName("com.acme.SecretClass");
} catch (ClassNotFoundException e) {
    // Show dialog
}

这篇关于Java:运行时检查类是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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