2

I'm working on a program that utilizes Caprica's VLCJ Bindings.

This is fine and good for Windows and Mac, as I can just package the VLC Libraries for them in a zip file and output them to the user machine where appropriate.

The problem comes when I need to do this for Linux, because, dear god,

enter image description here

there are ELEVEN. SEPARATELY COMPILED. APPLICATIONS/LIBRARIES.

And some of them even have their own flavors. It's like the Baskin Robins of OS's (I knew there were a few but I've only really ever run Ubuntu so I was not prepared for this).

If I was a masochist I could totally make this work and end up with a gigantic jar with an absurdly huge number of zipped Linux libraries within it, but I really, reHEHEHEALLY do not want to do that.

So I figured that the best course of action to take would be to check if LibVLC is installed, and if it is, reference it directly, and if it isn't, install it at run time (before the library tries to load itself), or, heck, even at launch/install time for the Java program.

Is this possible? I know that on Ubuntu using the terminal it would be something similar to

sudo apt-get install vlc

and there's probably 15 different flavors of that, which is fine, I can deal with that, but is it possible to do that from within a running Java application (and wait until it's finished before moving on), and if so, how can I go about doing that, and if not, how hosed am I?

Will
  • 3,413
  • 7
  • 50
  • 107
  • I think this post is what you are looking for: http://stackoverflow.com/questions/3403226/how-to-run-linux-commands-in-java-code – Maux Sep 30 '14 at 20:19
  • I saw a few like that. Then my next question would be how do I determine if this current flavor of Linux has VLC installed on it? Am I forced to handle a thrown exception? – Will Sep 30 '14 at 20:20
  • 1
    looks like the kind of thing you won't want your automatic installer to deal with. Do you really need to support all linuxes distros? – Leo Sep 30 '14 at 20:21
  • Search apt-cache if package is installed: `apt-cache search vlc` – Maux Sep 30 '14 at 20:24
  • Really I probably don't need to support any of them but my employers client base is, well, people. And I can't account for what OS they might be using. I would be fine with managing like the top 2 most popular (which I'm guessing would be Ubuntu and OpenSUSE, but I'm not sure on that). – Will Sep 30 '14 at 20:24
  • @Will I'm facing this exact problem. What solution did you end up using? – Grumblesaurus Aug 05 '18 at 08:12
  • 1
    @JoshuaD I didn't, sorry. I've long since moved on from trying to do anything with Linux in this capacity. Hope you are able to find a solution. – Will Aug 05 '18 at 14:34

1 Answers1

4

To detect if LibVLC is already installed it's possible to do that in pure Java simply by searching the file-system using Java File IO. The idea is you'd look for "libvlc.so.*" in "/usr/lib" and/or other "well-known" locations.

vlcj provides a NativeDiscovery class that will do this for you:

boolean foundLibVLC = new NativeDiscovery().discover();

You can find Javadoc here.

You could then throw up a dialog box to prompt the user to install vlc using their package manager.

Or you could detect the OS by using Java File IO to read "/etc/issue" and if it were Ubuntu you could launch a process to run "apt-get install", or a different package manager for a different distro. I've used Apache Commons-Exec to do this sort of thing before.

There's simply no universal package manager you can assume across the different distros.

I know it's not ideal, but this is what I do for my projects.

To be fair, if you're targetting users on Linux you're likely to be targetting more technically savvy users than most and they would likely have no problems installing other software.

A further option I suppose is to ship the VLC source code with your project and have your installer build VLC. It takes a while to build VLC from scratch though, and there are lot of third party library dependencies that must be installed first.

I suppose on Linux, the 'correct' thing to do is to create a distro package (like a .deb or .rpm or something), declare a dependency on VLC, Java and JNA and do it that way.

caprica
  • 3,902
  • 4
  • 19
  • 39
  • That seems reasonable. Is VLC always put in the same directory in Linux, or is there a way (such as through that NativeDiscovery method) to find the directory in which it resides? – Will Sep 30 '14 at 20:56
  • If you use NativeDiscovery, I'm not sure why you need to know the actual directory as well. In any event, it's not too difficult to search "/usr/lib" or "/usr/local/lib" yourself. – caprica Oct 01 '14 at 06:09