简体   繁体   English

Eclipse RCP:检查本机库

[英]Eclipse RCP: Check for Native Library

In an Eclispe RCP application, is there a way to check whether a specific native library is available on the current system? 在Eclispe RCP应用程序中,是否有办法检查当前系统上是否有特定的本机库?

Using System.loadLibrary("myLib"); 使用System.loadLibrary(“ myLib”); and then catching an UnsatisfiedLinkError results in other bundles not being able to use the library, as this would lead to an error "Library already loaded by another class loader". 然后捕获UnsatisfiedLinkError导致其他捆绑软件无法使用该库,因为这将导致错误“库已由另一个类加载器加载”。

I've found a solution to this problem on the internet which uses a custom class loader, which then loads the library and then the class loader is garbage collected with System.gc(), which will also unload the library so it can be loaded again by another bundle. 我在互联网上找到了针对此问题的解决方案,该解决方案使用自定义类加载器,然后加载该库,然后使用System.gc()垃圾收集类加载器,该类加载器还将卸载该库,以便可以对其进行加载再次被另一个捆绑。

There are disadvantages however: 但是有一些缺点:

  1. It requires a lot of custom code 它需要很多自定义代码
  2. Catching UnsatfisfiedLinkError is somewhat scary 捕获UnsatfisfiedLinkError有点吓人
  3. Say Bundle1 loads the library to check for availability. 说Bundle1加载库以检查可用性。 Then Bundle1 unloads the library and Bundle2 loads the library to actually use it. 然后Bundle1卸载库,而Bundle2加载库以实际使用它。 Bundle2 does not unload the library (as there is no reason to do so). Bundle2不会卸载库(因为没有理由这样做)。 Then, Bundle1 again wants to load the library to check for availability. 然后,Bundle1再次想要加载库以检查可用性。 This again will lead to an UnsatisfiedLinkError. 这将再次导致UnsatisfiedLinkError。

ad 3.) First of all I would avoid to let bundles randomly load system libraries. 广告3.)首先,我将避免让捆绑包随机加载系统库。 Maybe you can pack the handling of the system library and all of its access in a service bundle? 也许您可以将系统库的处理及其所有访问权限打包在服务包中?

I agree, catching ERROR is not only scary, its probably not something we should do at all. 我同意,捕获错误不仅令人恐惧,而且可能根本不是我们应该做的事情。 Error is an VM error, and thats something which usually leads to a restart of your vm -or application in your case- to guarantee stable operation. 错误是VM错误,多数民众赞成在某些情况下通常会导致vm(或您的情况下的应用程序)重新启动,以确保稳定运行。

For me the check whether a library is available or not is similar to check whether a file resource exists or not. 对我来说,检查库是否可用类似于检查文件资源是否存在。 If libraries are something very dynamic in your application context you may either let the user browse for the library and let the application know where it is. 如果库在您的应用程序上下文中非常动态,则可以让用户浏览该库并让应用程序知道它的位置。 If there is no such thing like a user, can't u simply search for the file in the path of the client machine? 如果没有像用户这样的东西,您是否不能简单地在客户端计算机的路径中搜索文件?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM