1

I am using mediainfo (http://mediainfo.sourceforge.net/en) to extract information from audio and video files using Java code.

My java project runs over all platforms (osx, win & linux). So far I have only tested mediainfo over osx where the procedure is simple: just put libmediainfo.dylib in the target folder and access it using a native library and you're good to go. And the solution works flawlessly...

I am now looking to expand this functionality to the other OSs, starting with Linux. However, it is proving to be more of a challenge than I thought. At first I kept getting this:

"java.lang.UnsatisfiedLinkError: Unable to load library 'mediainfo': libmediainfo.so: cannot open shared object file: No such file or directory"

and this was expected as it was looking in /usr/lib

but this was solved by installing the suitable libmediainfo0 & libzen0 ".deb from http://mediainfo.sourceforge.net/en/Download/Ubuntu

Still, my solution needs to be portable, meaning, I want all necessary resources to be included with the java project package without requiring any further installations. I also need to know if it's possible to change mediainfo to look for the resources in my java package instead of a system location.

For your reference, I am using Java Native Access (jna) to interact with the library. Also using the MediaInfo.java & MediaInfoLibrary.java classes that the website suggests. Let me know if you need other details.

any wisdom is highly appreciated thanks!!

martinez314
  • 12,162
  • 5
  • 36
  • 63
static0886
  • 784
  • 9
  • 25
  • 1
    The latest release of JNA (3.5.2) will automatically unpack native libraries [bundled as resources](http://twall.github.io/jna/3.5.2/javadoc/com/sun/jna/NativeLibrary.html) (whether file- or jar-based). – technomage Apr 12 '13 at 21:08
  • Thanks for that. Could you elaborate a bit more on that? – static0886 Apr 15 '13 at 15:38
  • 1
    If you include you shared library for linux/amd64 as /linux-x86-64/libmylibrary.so in one of your jar files, JNA will extract it and load it automatically when you call `Native.loadLibrary("my library")`. Older versions of JNA require that you make the library available on `LD_LIBRARY_PATH` (envariable) or `jna.library.path` (system property). – technomage Apr 15 '13 at 18:22
  • that's it! it finally worked (@ least on linux for now) i added the resources in the jar file under "linux-i386" dir sweeeeet!! could you add your comment as an answer so I can accept it thx a million – static0886 Apr 19 '13 at 12:18

1 Answers1

2

The latest release of JNA (3.5.2) will automatically unpack native libraries bundled as resources (whether file- or jar-based).

If you include you shared library for linux/amd64 as /linux-x86-64/libmylibrary.so in one of your jar files, JNA will extract it and load it automatically when you call Native.loadLibrary("my library"). Older versions of JNA require that you make the library available on LD_LIBRARY_PATH (envariable) or jna.library.path (system property).

technomage
  • 9,861
  • 2
  • 26
  • 40
  • just as an extra, for ubuntu 12.04 i386 the resources (libmediainfo.so & libzen.so) had to be placed in a dir named linux-i386. How can i tell what names should other folders have on other platforms?? – static0886 Apr 19 '13 at 15:04
  • 1
    `Native.getNativeLibraryResourcePrefix()` (which will be an alias to `Platform.RESOURCE_PREFIX` in subsequent releases). – technomage Apr 19 '13 at 16:22