提供NetBeans中本机dll的自定义路径 [英] Giving custom path for native dll in Netbeans

查看:260
本文介绍了提供NetBeans中本机dll的自定义路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NetBeans平台应用程序,其中包含2个模块,这些模块具有同一本机库的不同版本.

I have a NetBeans platform application with 2 modules having different versions of same native library.

我在每个模块下的release/module/lib文件夹中添加了本机库. [按照 http://wiki.netbeans.org/DevFaqWrapperModules 部分:如何在我的库包装模块中包含本地库( .so或 .dll)?]

I added the native library inside release/module/lib folder under each module. [as per http://wiki.netbeans.org/DevFaqWrapperModules section: How do I include native libraries (.so or .dll) in my library wrapper module?]

但是问题是在应用程序的最终生成过程中,本机库被复制到build \ cluster \ modules \ lib文件夹中.即lib文件夹中仅存在我的本机库的一个版本,因为这两个版本具有相同的名称.现在我的问题是,我可以在Netbeans中特别提到jar(版本1)应采用本机lib(版本1),而jar(版本2)应引用本机lib(版本2).

But the problem is during the final build generation of the application, native libraries are copied to build\cluster\modules\lib folder. i.e only one version of my native library exists inside lib folder as both versions have same name. Now my question is can I specifically mention in Netbeans that jar (Version 1) should take native lib (ver1) and jar (Version 2) should refer to native lib (version 2).

推荐答案

您可以通过两种方式加载本机库文件(.dll/Windows或.so/Linux):

You can load a Native library file (.dll/Windows or .so/Linux) with two ways:

1)通过提供完整路径来加载文件:

1) Load the file by providing the full path:

System.load("my/full/path/native.dll");

2)如果您的本机文件位于Java库路径内:

2) If your native file is located inside your Java Library Path:

System.loadLibrary("native");

请注意,在第二种情况下,您只需要提供本机文件的名称(不带扩展名).

Take notice that in the second case you only need to provide the name of your native file (without its extension).

默认的Java库路径取决于操作系统:

The default Java Library Path depends on OS:

在Windows上,它映射到PATH
在Linux上,它映射到LD_LIBRARY_PATH
在OS X上,它映射到DYLD_LIBRARY_PATH

On Windows, it maps to PATH
On Linux, it maps to LD_LIBRARY_PATH
On OS X, it maps to DYLD_LIBRARY_PATH

如果要设置自己的Java库路径:

If you want to set your own Java Library Path:

try {
        System.setProperty("java.library.path","YOUR/PATH");
        Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
        fieldSysPath.setAccessible(true);
        fieldSysPath.set(null, null);
    } catch (Exception ex) {
        System.out.println("Failed to set Java Library Path: " + ex.getMessage);
    }

这篇关于提供NetBeans中本机dll的自定义路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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