tags:

views:

1377

answers:

2

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?

+1  A: 

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.

kaliatech
Nope, specifically refering to defining Libraries that can be added to projects.
Allain Lalonde
Nugget in there regarding packaging the dll within the jar is interesting.
Allain Lalonde
+1  A: 

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.

domenico