Question

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?

Was it helpful?

Solution

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:

Additional information here:

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.

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.

OTHER TIPS

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.

I tested the following solution while using NetBeans 7.0.1 and it worked, but I don't know if it works in early versions, too.

The solution is easy and works per NetBeans module. So, if you have a suite, don't place its JNI files into suite project, instead, place the JNI files that you want into the module itself. Do:

  1. Find a NetBeans module project that you want (or need, or think) to place your JNI libraries (them with extension .DLL, .so and .jnilib, by eg);
  2. At Projects, right click at the module node, click at Properties menu;
  3. In the Project Properties dialog, click at Libraries and Wrapped JARs. You must add any external library there. I added the RxTX jar library. After add your external libraries, the Netbeans Ant script will copy all files/folders from the directory your_project_dir/release to the right location when you build the solution.
  4. So, place your native libraries at your_project_dir/release/lib. If you want, you can create subdirectories for each target platform that you need, as: your_project_dir/release/lib/amd64, your_project_dir/release/lib/sparc32

    To know, more, read: http://bits.netbeans.org/dev/javadoc/org-openide-modules/org/openide/modules/doc-files/api.html#jni

    Regards, marciowb.info

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top