我有一个 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 中的用户机器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
解析 ISO 8601 字符串本地日期时间,就像在 UTC 中Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期时间,就像在 UTC 中一样)
如何将公历字符串转换为公历?How to convert Gregorian string to Gregorian Calendar?(如何将公历字符串转换为公历?)
Java:GregorianCalendar 的最大值和最小值是什么/在哪Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
1582 年 10 月 15 日之前日期的日历到日期转换.公历Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日历到日期转换
java日历setFirstDayOfWeek不起作用java Calendar setFirstDayOfWeek not working(java日历setFirstDayOfWeek不起作用)
Java:获取当前星期几的值Java: getting current Day of the Week value(Java:获取当前星期几的值)