Embedded native library in the JAR file

569 views
Skip to first unread message

Zlika

unread,
Sep 5, 2012, 4:05:33 AM9/5/12
to jna-...@googlegroups.com
Hi !

I would like to produce a single JAR file containing both the JNA Java wrapper for my native library AND the native library itself (libXxx.so).
I found a possible solution to do that using BridJ (cf. http://code.google.com/p/bridj/wiki/LibrariesLookup) but I wasn't able to find anything for JNA.
Is it possible to do that using JNA ?

Thank you for your answers.
Regards,
Thomas

Kustaa Nyholm

unread,
Sep 5, 2012, 4:17:28 AM9/5/12
to jna-...@googlegroups.com
How about OneJar? I've used it succesfully package JOGL and the associated
native libraries .... it might Just Work (tm) but have not tried it with
JNA.


http://one-jar.sourceforge.net

Just a thought.

br Kusti

Timothy Wall

unread,
Sep 5, 2012, 6:45:24 AM9/5/12
to jna-...@googlegroups.com
JNA doesn't provide a method for doing so, since the specific needs may vary widely from application to application.

You can, however, use JNA's pattern of storage and unpacking its own native library from the Native.loadNativeLibraryFromJar() function.

If you feel this is something that should be exposed, feel free to do a pull request.

Zlika

unread,
Sep 5, 2012, 11:32:56 AM9/5/12
to jna-...@googlegroups.com
Thank you for your answer. I will do something similar than what is done in Native.loadLibraryFromJar().
 
But I think it would be an interesting feature for JNA to propose a transparent way to load a native library from the current JAR, in a similar way as BridJ do, because I've read lots of forum messages from people having a similar problem with JNA.
 

François

unread,
Oct 4, 2012, 8:17:13 AM10/4/12
to jna-...@googlegroups.com
I'm using ant and genjar to build jars and these lines could build a single jar file.  I had to put the dll in a folder on my disc, since I was not able to get it directly from the jna.jar file, but at the end I got a single jar working.

François
   
<genjar jarfile="${allproj.dir}/${proj.dir}/${bigjar.file}">
     <!-- include main class and all its dependencies -->
     <class name="${main.class}" />
      <classpath refid="class.path" />
    <classfilter>
        <include name="com.sun.jna." />
    </classfilter>
    <resource  package="com.sun.jna.win32-amd64">
        <fileset dir="${basedir}/aux_dll" >
            <include name="*.dll" />
        </fileset>
    </resource>
Reply all
Reply to author
Forward
0 new messages