Configuring libmediainfo to work with Java project without installation across all platforms (OSes)

StackOverflow https://stackoverflow.com/questions/15975296

Question

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!!

Was it helpful?

Solution

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top