title: Encapsulating a JNI library inside a jar file
body: <p>I am trying to develop a plugin for Fiji/ImageJ that relies on a native library (JNI).
  The JNI library itself depends on <code>libtiff</code> and <code>fftw</code>. On OSX and Linux, I use the class <a href="https://github.com/adamheinrich/native-utils" rel="nofollow noreferrer">NativeUtils</a> and everything works fine.</p>
  
  <p>On windows, I included binary versions of <code>libtiff</code> and <code>fftw</code> in the <code>CMake</code> package and managed to link the JNI library against those (either statically of dynamically). However, the resulting JNI module does not include <code>libtiff</code> or <code>fftw</code> and I obtain an error when I try to load the JNI library with <code>NativeUtils.loadLibraryFromJar</code>. This is also the case when I include the dependent <code>.dll</code> in the <code>.jar</code> since they are not extracted by <code>NativeUtils</code>.</p>
  
  <p>Here are the relevant lines in <code>CMakeLists.txt</code>:</p>
  
  <pre><code>add_library(fftw STATIC IMPORTED GLOBAL)
  set_target_properties(fftw PROPERTIES IMPORTED_LOCATION "${libdir}/libfftw3f-3.lib"
                                        INTERFACE_INCLUDE_DIRECTORIES  "${incdir}")
  
  SWIG_ADD_LIBRARY(javainterf
                   TYPE MODULE
                   LANGUAGE java
                   SOURCES javainterf.i javainterf.c src1.c)
  SWIG_LINK_LIBRARIES(javainterf libcode1 fftw)
  
  add_jar(Foo
          SOURCES ${CMAKE_CURRENT_BINARY_DIR}/java/foo1.java
          INCLUDE_JARS java/resources/ij-1.51p.jar
          VERSION ${JAR_VERSION})
  add_dependencies(Foo javainterf)
  add_custom_command(TARGET Foo POST_BUILD
      COMMAND "${Java_JAR_EXECUTABLE}" -uf Foo-${JAR_VERSION}.jar
      -C ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR} ${JNI_LIB_NAME})
  </code></pre>
  
  <p>How would you make sure that all the dependencies are properly included in the jar and loaded?</p>