关于Native Library在NetbeansRCP应用中的设置

在Netbeans RCP中利用JMF框架实现音频视频的传输,开始就遇到一个问题,网上搜索了一下,与下面这个类似,直接贴过来吧

 ——————————————————————————————————————————————————————————————

http://stackoverflow.com/questions/5887383/netbeans-platform-application-doesnt-detect-webcam-devices-with-jmf
 

I've been trying to develop an application with Netbeans RCP to grab images from a webcam. Plain and simple, it works in a regular Java project.

So first of all the JMF must be installed (I'm on Windows 7 64bit, (32bit JDK which is needed for JMF).

In a regular Java project I have the following code:

Vector webcams = CaptureDeviceManager.getDeviceList(null);
int length = webcams.size();
System.out.println("length: " +length);

The output for this is "length: 1" (1 webcam connected)

When I do this in my Netbeans platform project this output is "length: 0".

So basicly I have my Netbeans project suite 2 modules:

  • JMF libraries (wrapper module with jmf.jar)
  • Webcam module (contains 1 java file with the above code)

I added the JMF libraries module to the Webcam module as a Dependency but this didn't do the trick. I can also confirm that the classpath is set:

Boot & Ext. Classpath   = C:\Program Files (x86)\Java\jdk1.6.0_25\jre\lib\resources.jar;C:\Program Files (x86)\Java\jdk1.6.0_25\jre\lib\rt.jar;
C:\Program Files (x86)\Java\jdk1.6.0_25\jre\lib\sunrsasign.jar;C:\Program Files (x86)\Java\jdk1.6.0_25\jre\lib\jsse.jar;
C:\Program Files (x86)\Java\jdk1.6.0_25\jre\lib\jce.jar;C:\Program Files (x86)\Java\jdk1.6.0_25\jre\lib\charsets.jar;C:\Program Files (x86)\Java\jdk1.6.0_25\jre\lib\modules\jdk.boot.jar;C:\Program Files (x86)\Java\jdk1.6.0_25\jre\classes;C:\Program Files (x86)\Java\jdk1.6.0_25\jre\lib\ext\dnsns.jar;**C:\Program Files (x86)\Java\jdk1.6.0_25\jre\lib\ext\jmf.ja**r;
C:\Program Files (x86)\Java\jdk1.6.0_25\jre\lib\ext\localedata.jar;C:\Program Files (x86)\Java\jdk1.6.0_25\jre\lib\ext\sound.jar;C:\Program Files (x86)\Java\jdk1.6.0_25\jre\lib\ext\sunjce_provider.jar;
C:\Program Files (x86)\Java\jdk1.6.0_25\jre\lib\ext\sunmscapi.jar;C:\Program Files (x86)\Java\jdk1.6.0_25\jre\lib\ext\sunpkcs11.jar

I am really stuck here. What is so special about Netbeans RCP that adding jmf.jar as a wrapper module seems to break this code?

If someone has some tips to help get more debug information to trace the problem I'm very grateful.

EDIT:

After a lot of trial and error I found the following solution:

Copy c:\Progra.... x86\JMF...\lib\* to c:\Program .. x86\jdk\lib\*
Including the jmf.properties file

However I am happy that this works, once the app transfer to another client PC for usage it will not have those libs there.

So I really don't know how to solve this problem with Netbeans RCP. How hard can it be? I added the jars to the wrapper, I placed the .properties file in the /release/modules/ext folder as well.

Please help me out here :)

————————————————————————————————————————————————————————————————————————

 上面最后提出了一个可行的解决方法,但不够好。下面是一些在Netbeans RCP中相关的设置native lib的方法:

http://deadlock.netbeans.org/hudson/job/faqsuck/lastSuccessfulBuild/artifact/other/faqsuck/build/faq.html#DevFaqNativeLibraries
 

DLLs or SOs can be placed in the folder release/modules/lib/ in a module project's sources (look in the Files tab). This will make them appear in the final NBM or application in a lib subdirectory beneath where the module's JAR resides. Then just use System.loadLibrary as usual.

API Reference: JNI in modules

Applies to: NetBeans 6.8 and above

 ————————————————————————————————————————————————————————————————————————

http://bits.netbeans.org/dev/javadoc/org-openide-modules/org/openide/modules/doc-files/api.html#jni

JNI

It is possible to run modules making use of JNI native implementations inside NetBeans. You may place the native libraries (DLL or shared-object) beneath a modules/lib directory (i.e. a subdirectory lib/ beneath the directory where the module JAR resides). If your native library file names for different architectures or operating systems clash, you may create subdirectories under modules/lib for each supported platform and nested subdirectories for each supported operating system. The directory names must match System.getProperty ("os.arch") and System.getProperty ("os.name").toLowerCase () respectively. The System.loadLibrary call originating from the module code will try to locate the library file in the following order of directories:

  • modules/lib/
  • modules/lib/<arch>/
  • modules/lib/<arch>/<os>/

so you may place e.g. 64bit linux version of a foo library in a file modules/lib/amd64/linux/libfoo.so. The module may distinguish additional library variants itself or even override the platform selection logic by naming the library file appropriately and calling System.loadLibrary with such a name. Use of JNI is of course not recommended and should be restricted to cases where it is unavoidable.

Example of usage: if on Linux a module located in /home/app/cluster/modules/something.jar calls System.loadLibrary("stuff-linux-i386-gnome"), the library should be in /home/app/cluster/modules/lib/libstuff-linux-i386-gnome.so. On 64bit Windows, if C:\app\cluster\modules\something.jar calls System.loadLibrary("stuff"), the library should be in C:\app\cluster\modules\lib\amd64\stuff.dll. (Remember that Java has platform-specific prefixes and suffixes it adds to plain library names before trying to find it on disk.)

If a native library refers to other native libraries, they are likely to be found using the normal search path for the platform. This may mean that if you have several libraries used in a module, you must either put all but the directly referenced one in the system's global library search path, or merge them all together.

Warning: since the JVM cannot load the same native library twice even in different classloaders, a module making use of this feature cannot be enabled more than once in a single VM session. JARs loaded from the classpath (application classloader) are never reloaded, so it may be possible to include the native-dependent classes in such a JAR and make use of it from a module JAR.

NetBeans currently includes a JNA wrapper module which can also be used for native access. As of this writing, however, this module exports only a friend API, so it is not available for use from arbitrary modules.

 ————————————————————————————————————————————————————————————————————

待我试下效果如何!

 晕,全部管用,又找了一个,待我试试!

http://www.java.net/node/680780
jcd
Offline
Joined: 2005-06-06

Hi All,
I have a netbeans RCP application in which I replaced JEditPane by jdic WebBrowser but I always get the following message:

java.lang.UnsatisfiedLinkError: Expecting an absolute path of the library: null\jdic.dll
at java.lang.Runtime.load0(Runtime.java:767)
at java.lang.System.load(System.java:1005)
at org.jdesktop.jdic.init.JdicManager$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at org.jdesktop.jdic.init.JdicManager.loadLibrary(Unknown Source)
at org.jdesktop.jdic.browser.WebBrowser.(Unknown Source)

I have inserted a property in the project file:
run.args.extra=-J-Djava.library.path="C:\\jisis-01-10-2007\\jisis\\jdic.dll"

And I can see the interpreted VM option when running the application:
Input arguments:
-Dnetbeans.logger.console=true
-ea
-Djava.library.path=C:\jisis-01-10-2007\jisis\jdic.dll
-Djdk.home=C:\Program
Files\Java\jdk1.6.0_02

Any Help would be appreciated, Thanks in advance

jcd

***********

jcd
Offline
Joined: 2005-06-06

[u]Here is how I solved the issue:[/u]

I experienced problems when trying to use the latest release jdic-0.9.5-bin-cross-platform.zip and jdic-20061102-bin-crossplatform.zip. Thus I decided to try with the jdic-20061102-bin-win release

1) I created a library wrapper module for jdic providing jdic.jar as library

When executing my application, I noticed the following message:
[b]native lib path ….\build\cluster\modules\ext[/b]

From this message, I concluded that I should copy all native libraries into the
[b]…\build\cluster\modules\ext[/b]

2) I copied the whole bunch of jdic files into this folder: MozEmbed.exe, IeEmbed.exe, jdic.dll and tray.dll. jdic.jar was already there, copied by NetBeans.
My application worked perfectly

3) But I was loosing the jdic files each time I was cleaning and re-building the application.
Thus I copied the jdic files in the [b]…\jdic\release\modules\ext[/b] folder of the [b]jdic library wrapper module[/b]. And now the files are copied by NetBeans in the [b]….\build\cluster\modules\ext[/b]
and my application works fine.

Please note that it may be worth to try again the jdic-20061102-bin-crossplatform.zip and using the same process.

Hope you will find this useful, best wishes

JCD

 

 ————————————————————————————————————————————————————————————————————————

还是第一个方法管用!!!

——————————————————————————————————
傲轩游戏网
原文地址:https://www.cnblogs.com/cuizhf/p/2232807.html