Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NetBeans Library using JNI

Can I have a Library defined that makes use of JNI in NetBeans?

Seems the library definition only allows Jars or Folders.

How can I assure that the DLL follows the jar file when the app is built?

like image 696
Allain Lalonde Avatar asked Jan 13 '09 19:01

Allain Lalonde


People also ask

How add C++ to NetBeans?

Now you need to configure NetBeans IDE. From the main menu select Tools → Options and in the popup window that appears, click on the C/C++ icon to open the “Options” dialog box of C/C++, as shown in Figure 6. Notice: If Cygwin is not installed on your system, read and follow the instructions shown here.

What is JNI Bridge?

Introduction to Java Native Interface: Establishing a bridge between Java and C/C++ JNI (Java Native Interface) is a foreign function interface that allows code running on JVM to call (or be called by) native applications. Using JNI, one can call methods written in C/C++ or even access assembly language.


2 Answers

Assuming you are referring to building a NetBeans Platform App (or module), then you can place the DLL in the "release/modules/lib/" folder. This is per the platform FAQ:

  • http://wiki.netbeans.org/DevFaqNativeLibraries

Additional information here:

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

If you are asking more generally, then I think most people package the DLL inside the jar, then extract it to a temp location upon application startup. e.g.

  • How to make a JAR file that includes DLL files?

If that's not what you're looking for, then you'll need to provide more information as to what you're trying to do.

like image 87
kaliatech Avatar answered Sep 17 '22 12:09

kaliatech


netbeans won't do it on its own, but since it uses ant behind the scenes there's a workaround.

you should create a subdirectory named jni in your project directory (c:\path\to\mynetbeansproject\jni), put all the .dll, .so and .jnilib files in there (the native stuff), and add the following lines to the build.xml file you find in your project directory, just before the </project> tag:

<target name="-post-compile">
    <copy todir="${dist.dir}/lib">
        <fileset dir="jni" />
    </copy>
</target>

then add the jar file to your project just like you always do. :)

the snippet you inserted in build.xml will make sure that the native libraries follow your jar files in the dist/lib folder when you invoke "Clean and Build" from within netbeans (or ant from the command line); the jvm will look for the .dll (.so, .jnilib) files in the same directory as the .jar that's loading them, so it will work.

note that this won't make your project run from within netbeans, because… I'm not really sure what goes on, but it looks like the library path (LD_LIBRARY_PATH) doesn't include your projects' libraries, and there's no way I know of changing it from within netbeans. just put your native libraries in /Library/Java/Extensions on mac os x, or just stash them in c:\windows\system32 under windows. if you're running a 64 bit windows with a 64 bit jvm, I have no clue; if you're running linux, you probably know where to stash them, but /usr/lib/java might be a good bet.

like image 35
domenico Avatar answered Sep 20 '22 12:09

domenico