简体   繁体   中英

How can I tell a Linux Distro to apt-get install LibVLC if it doesn't have it from a running Java Program?

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,

在此处输入图片说明

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM