問題描述
我有一個 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模板網!