4

I am using JNAerator to generate a single jar file I can include in a project, and I'd like to support the dynamic libraries for each operating system and arch all in this single jar.

In fiddling with JNAerator so far, I've been able to include a single dynamic library using a command like the following:

java -jar jnaerator.jar test.dll test.h [...] -mode StandaloneJar

However, this only packages test.dll, while I have dynamic libraries for multiple systems (test_win32.dll, test_win64.dll, libtest_mac.dylib, libtest_linux_x86.so, and libtest_linux_amd64.so) which I would like to all have packaged into and supported by one jar.

Is there any way to do this "all-in-one" approach with one run of JNAerator, or must I generate a different jar file for each platform?

FThompson
  • 28,352
  • 13
  • 60
  • 93
  • Hi FThompson, when I created JAR of it, inside that how I can get the JNA filed to use that in my Java project? Were you able to get that? – Gaurav Jeswani Jul 31 '19 at 09:17

1 Answers1

10

JNAerator has an -arch option designed just for that, although the doc is currently terribly vague about it:

java -jar jnaerator-0.12-shaded.jar \
  -arch win32 win32/test.dll \
  -arch win64 win64/test.dll \
  -arch darwin_universal mac/libtest.dylib \
  -arch linux_x86 linux_x86/libtest.so \
  -arch linux_x64 linux_amd64/libtest.so \
  test.h \
  -mode StandaloneJar \
  -jar test.jar

This will bundle the libraries under the format expected by BridJ (see its wiki page about embedded binaries):

unzip -l test.jar gives:

    ...
    0  04-09-15 22:45   lib/win32/test.dll
    0  04-09-15 22:45   lib/win64/test.dll
    0  04-09-15 22:45   lib/darwin_universal/libtest.dylib
    0  04-09-15 22:45   lib/linux_x86/libtest.so
    0  04-09-15 22:45   lib/linux_x64/libtest.so

The library names are currently expected to be exactly lib<name>.(so|dylib) or <name>.dll for every platform, although that could easily be fixed if you ask.

(note: I'm the author of BridJ & JNAerator)

zOlive
  • 1,768
  • 13
  • 11
  • 1
    Perfect, thanks! Look forward to some bounty reputation once I can (due to the two-day limit) as a thank you for both this answer and your great work on JNAerator and your other projects :) – FThompson Apr 09 '15 at 22:07
  • Hi zOlive, when I created JAR of it, inside that how I can get the JNA filed to use that in my Java project? – Gaurav Jeswani Jul 31 '19 at 09:16