问题描述
我有一个 Java 应用程序,它需要某些软件(其中之一是 Perl)才能运行.我用来检测 Perl 的方法是:
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");
如果有 IOException 则声明没有 Perl.
and if there was an IOException declare that there was no Perl.
但是,我的一位用户抱怨该应用程序一直失败,因为他没有将 Perl 放在他的路径变量中.所以这就是我要问的原因:是否有任何跨操作系统的方法来检测用户系统上是否安装了 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?
推荐答案
我不知道你的目标受众(用户),但失败时你可以提示用户输入路径(一个 FileChooserDialog)然后存储这个路径以备将来使用(如果没有再次抛出异常).前段时间我这样做了,幸运的是我的用户是系统管理员,所以他们可以在第一次发生错误时提供该信息(我还记录了如何在属性文件中更新或更改这些值).
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).
Don 提到的其他选项是安装相对于您的安装所需的软件,这是一个更常见的选项.
Other option as mentioned by Don, is to install the required software as relative to your installation, that's a more common option.
这篇关于检测某些软件是否安装在 Java 中的用户机器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!