javaoperating-systemdetect

Detect if certain software is installed on a user's machine in Java


I have a Java application which requires certain software (one of them being Perl) before it can be run. What I used to do to detect for Perl is:

Runtime.getRuntime().exec("perl Test.pl");

and if there was an IOException declare that there was no Perl.

However, one of my users complained that the app kept failing because he had not placed Perl in his path varible. So this is why I'm asking: Is there any cross-operating system way to detect whether Perl (or any other software) is installed on the user's system and the path to the program?


Solution

  • I don't know your target audience (users), but upon failure you could prompt the user to enter the path (a FileChooserDialog) and then store this path for future usage (if the exception is not thrown again). I did that some time ago, luckily I had users that were SysAdmins, so it was OK for them to provide that info when the error happened the first time (I also documented how to update or change these values in a properties file).

    Other option as mentioned by Don, is to install the required software as relative to your installation, that's a more common option.