简体   繁体   English

在netbeans中为.dll / .so文件提供'java.library.path'

[英]giving 'java.library.path' in netbeans for .dll/.so files

How do i give the path for the .dll or .so file in netbeans to load the library using 如何为netbeans中的.dll.so文件提供路径以使用加载库

System.loadLibrary("Foo")

I read this on netbeans page but couldn't help me. 在netbeans页面上看到了这个但是无法帮助我。 as it gives the unsatisfied link error. 因为它给出了不满意的链接错误。

These are the two things i tried : 这是我尝试的两件事:

In the following snapshot i created a lib folder inside the netbeans project and placed the dll files inside it. 在下面的快照中,我在netbeans项目中创建了一个lib文件夹,并将dll文件放在其中。

在此输入图像描述

In the second snapshot i created a lib folder inside the modules folder and placed all the dll files inside lib folder as stated in the link . 在第二个快照中,我在modules文件夹中创建了一个lib文件夹,并将所有dll文件放在lib文件夹中,如链接中所述。

在此输入图像描述

But both of them give me unsatisfied link error exception. 但是他们俩都给我unsatisfied link error异常。 How do i set java.library.path in netbeans so that i can directly test the application from netbeans, without having to go and write on the terminal ? 如何在netbeans中设置java.library.path ,以便我可以直接从netbeans测试应用程序,而无需在终端上写入?

Its working now. 它现在正在工作。 Some little bit setting you have to do with your Netbean IDE.Only of Netbean IDE. 您可以使用Netbean IDE进行一些设置。仅限Netbean IDE。

Follow the Steps :- 按照步骤 :-

==>Right click on the Project
==>Properties
==>Click on RUN
==>VM Options : -Djava.library.path="C:\Your Directory where Dll is present"
==>Ok

Its working 100%. 它的工作率为100%。 I have done this in my own project. 我在自己的项目中完成了这个。

I'm using Mac OS X Yosemite and Netbeans 8.02, I got the same error and the simple solution I have found is like above, this is useful when you need to include native library in the project. 我正在使用Mac OS X Yosemite和Netbeans 8.02,我得到了同样的错误,我发现的简单解决方案如上所述,当您需要在项目中包含本机库时,这非常有用。 So do the next for Netbeans: Netbeans的下一步也是如此:

1.- Right click on the Project
2.- Properties
3.- Click on RUN
4.- VM Options: java -Djava.library.path="your_path"
5.- for example in my case: java -Djava.library.path=</Users/Lexynux/NetBeansProjects/NAO/libs>
6.- Ok

I hope it could be useful for someone. 我希望它对某人有用。 The link where I found the solution is here: java.library.path – What is it and how to use 我找到解决方案的链接在这里: java.library.path - 它是什么以及如何使用

IF you are working on "NetBeans Modules" 如果您正在使用“NetBeans模块”

DLLs or SOs can be placed in the folder release/modules/lib/ in a module project's sources (look in the Files tab). DLL或SO可以放在模块项目源中的文件夹release / modules / lib /中(查看Files选项卡)。 This will make them appear in the final NBM or application in a lib subdirectory beneath where the module's JAR resides. 这将使它们出现在模块的JAR所在的lib子目录下的最终NBM或应用程序中。 Then just use System.loadLibrary as usual. 然后像往常一样使用System.loadLibrary。

To me JDeveloper's suggestion didn't work. 对我来说JDeveloper的建议没有用。 However, the method that I came across this early afternoon works handy. 然而,我在这个下午早些时候遇到的方法很方便。 It is for netbeans 8.02, and Visual Studio 2013 generated dll. 它适用于netbeans 8.02,而Visual Studio 2013生成了dll。

  1. create a package(eg, "dll") under [Source Packages] node of netbeans project 在netbeans项目的[Source Packages]节点下创建一个包(例如“dll”)
  2. put/copy a dll file(eg, simpleDLL.dll) into the package(eg, "dll") 将dll文件(例如,simpleDLL.dll)放入/复制到包中(例如,“dll”)
  3. on the [Libraries] node of the netbeans project, right-click and choose "Add Jar/Folder...", 在netbeans项目的[Libraries]节点上,右键单击并选择“Add Jar / Folder ...”,
  4. navigate to the folder("src") that contains the folder("dll") for the package that you created in step 1 above (it could be "...\\src\\dll" in my example), select package folder("dll") and click [Open] button to select it. 导航到包含您在上面的步骤1中创建的包的文件夹(“drc”)的文件夹(“src”)(在我的示例中可能是“... \\ src \\ dll”),选择包文件夹( “dll”)并单击[打开]按钮将其选中。

-- now you should have added a folder("dll") (which contains the dll file{simpleDLL.dll}) to the Libraries node of the project. - 现在您应该将一个文件夹(“dll”)(其中包含dll文件{simpleDLL.dll})添加到项目的Libraries节点。

That's it. 而已。 It should work! 它应该工作! Good luck. 祝好运。

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

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